[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10157":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":22,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":16,"starSnapshotCount":16,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},10157,"node-fs-extra","jprichardson\u002Fnode-fs-extra","jprichardson","Node.js: extra methods for the fs object like copy(), remove(), mkdirs()","",null,"JavaScript",9609,783,90,14,0,5,65.18,"MIT License",false,"master",true,[24,25,26,27,28,29,30],"copy","delete","filesystem","javascript","move","nodejs","remove","2026-06-12 04:00:49","Node.js: fs-extra\n=================\n\n`fs-extra` adds file system methods that aren't included in the native `fs` module and adds promise support to the `fs` methods. It also uses [`graceful-fs`](https:\u002F\u002Fgithub.com\u002Fisaacs\u002Fnode-graceful-fs) to prevent `EMFILE` errors. It should be a drop in replacement for `fs`.\n\n[![npm Package](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Ffs-extra.svg)](https:\u002F\u002Fwww.npmjs.org\u002Fpackage\u002Ffs-extra)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fl\u002Ffs-extra.svg)](https:\u002F\u002Fgithub.com\u002Fjprichardson\u002Fnode-fs-extra\u002Fblob\u002Fmaster\u002FLICENSE)\n[![build status](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002Fjprichardson\u002Fnode-fs-extra\u002Fci.yml?branch=master)](https:\u002F\u002Fgithub.com\u002Fjprichardson\u002Fnode-fs-extra\u002Factions\u002Fworkflows\u002Fci.yml?query=branch%3Amaster)\n[![downloads per month](http:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdm\u002Ffs-extra.svg)](https:\u002F\u002Fwww.npmjs.org\u002Fpackage\u002Ffs-extra)\n[![JavaScript Style Guide](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcode_style-standard-brightgreen.svg)](https:\u002F\u002Fstandardjs.com)\n\nWhy?\n----\n\nI got tired of including `mkdirp`, `rimraf`, and `ncp` in most of my projects.\n\n\n\n\nInstallation\n------------\n\n    npm install fs-extra\n\n\n\nUsage\n-----\n\n### CommonJS\n\n`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are attached to `fs-extra`. All `fs` methods return promises if the callback isn't passed.\n\nYou don't ever need to include the original `fs` module again:\n\n```js\nconst fs = require('fs') \u002F\u002F this is no longer necessary\n```\n\nyou can now do this:\n\n```js\nconst fs = require('fs-extra')\n```\n\nor if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want\nto name your `fs` variable `fse` like so:\n\n```js\nconst fse = require('fs-extra')\n```\n\nyou can also keep both, but it's redundant:\n\n```js\nconst fs = require('fs')\nconst fse = require('fs-extra')\n```\n\n**NOTE:** The deprecated constants `fs.F_OK`, `fs.R_OK`, `fs.W_OK`, & `fs.X_OK` are not exported on Node.js v24.0.0+; please use their `fs.constants` equivalents. \n\n### ESM\n\nThere is also an `fs-extra\u002Fesm` import, that supports both default and named exports. However, note that `fs` methods are not included in `fs-extra\u002Fesm`; you still need to import `fs` and\u002For `fs\u002Fpromises` seperately:\n\n```js\nimport { readFileSync } from 'fs'\nimport { readFile } from 'fs\u002Fpromises'\nimport { outputFile, outputFileSync } from 'fs-extra\u002Fesm'\n```\n\nDefault exports are supported:\n\n```js\nimport fs from 'fs'\nimport fse from 'fs-extra\u002Fesm'\n\u002F\u002F fse.readFileSync is not a function; must use fs.readFileSync\n```\n\nbut you probably want to just use regular `fs-extra` instead of `fs-extra\u002Fesm` for default exports:\n\n```js\nimport fs from 'fs-extra'\n\u002F\u002F both fs and fs-extra methods are defined\n```\n\nSync vs Async vs Async\u002FAwait\n-------------\nMost methods are async by default. All async methods will return a promise if the callback isn't passed.\n\nSync methods on the other hand will throw if an error occurs.\n\nAlso Async\u002FAwait will throw an error if one occurs.\n\nExample:\n\n```js\nconst fs = require('fs-extra')\n\n\u002F\u002F Async with promises:\nfs.copy('\u002Ftmp\u002Fmyfile', '\u002Ftmp\u002Fmynewfile')\n  .then(() => console.log('success!'))\n  .catch(err => console.error(err))\n\n\u002F\u002F Async with callbacks:\nfs.copy('\u002Ftmp\u002Fmyfile', '\u002Ftmp\u002Fmynewfile', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\n\u002F\u002F Sync:\ntry {\n  fs.copySync('\u002Ftmp\u002Fmyfile', '\u002Ftmp\u002Fmynewfile')\n  console.log('success!')\n} catch (err) {\n  console.error(err)\n}\n\n\u002F\u002F Async\u002FAwait:\nasync function copyFiles () {\n  try {\n    await fs.copy('\u002Ftmp\u002Fmyfile', '\u002Ftmp\u002Fmynewfile')\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\ncopyFiles()\n```\n\n\nMethods\n-------\n\n### Async\n\n- [copy](docs\u002Fcopy.md)\n- [emptyDir](docs\u002FemptyDir.md)\n- [ensureFile](docs\u002FensureFile.md)\n- [ensureDir](docs\u002FensureDir.md)\n- [ensureLink](docs\u002FensureLink.md)\n- [ensureSymlink](docs\u002FensureSymlink.md)\n- [mkdirp](docs\u002FensureDir.md)\n- [mkdirs](docs\u002FensureDir.md)\n- [move](docs\u002Fmove.md)\n- [outputFile](docs\u002FoutputFile.md)\n- [outputJson](docs\u002FoutputJson.md)\n- [pathExists](docs\u002FpathExists.md)\n- [readJson](docs\u002FreadJson.md)\n- [remove](docs\u002Fremove.md)\n- [writeJson](docs\u002FwriteJson.md)\n\n### Sync\n\n- [copySync](docs\u002Fcopy-sync.md)\n- [emptyDirSync](docs\u002FemptyDir-sync.md)\n- [ensureFileSync](docs\u002FensureFile-sync.md)\n- [ensureDirSync](docs\u002FensureDir-sync.md)\n- [ensureLinkSync](docs\u002FensureLink-sync.md)\n- [ensureSymlinkSync](docs\u002FensureSymlink-sync.md)\n- [mkdirpSync](docs\u002FensureDir-sync.md)\n- [mkdirsSync](docs\u002FensureDir-sync.md)\n- [moveSync](docs\u002Fmove-sync.md)\n- [outputFileSync](docs\u002FoutputFile-sync.md)\n- [outputJsonSync](docs\u002FoutputJson-sync.md)\n- [pathExistsSync](docs\u002FpathExists-sync.md)\n- [readJsonSync](docs\u002FreadJson-sync.md)\n- [removeSync](docs\u002Fremove-sync.md)\n- [writeJsonSync](docs\u002FwriteJson-sync.md)\n\n\n**NOTE:** You can still use the native Node.js methods. They are promisified and copied over to `fs-extra`. See [notes on `fs.read()`, `fs.write()`, & `fs.writev()`](docs\u002Ffs-read-write-writev.md)\n\n### What happened to `walk()` and `walkSync()`?\n\nThey were removed from `fs-extra` in v2.0.0. If you need the functionality, `walk` and `walkSync` are available as separate packages, [`klaw`](https:\u002F\u002Fgithub.com\u002Fjprichardson\u002Fnode-klaw) and [`klaw-sync`](https:\u002F\u002Fgithub.com\u002Fmanidlou\u002Fnode-klaw-sync).\n\n\nThird Party\n-----------\n\n### CLI\n\n[fse-cli](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@atao60\u002Ffse-cli) allows you to run `fs-extra` from a console or from [npm](https:\u002F\u002Fwww.npmjs.com) scripts.\n\n### TypeScript\n\nIf you like TypeScript, you can use `fs-extra` with it: https:\u002F\u002Fgithub.com\u002FDefinitelyTyped\u002FDefinitelyTyped\u002Ftree\u002Fmaster\u002Ftypes\u002Ffs-extra\n\n\n### File \u002F Directory Watching\n\nIf you want to watch for changes to files or directories, then you should use [chokidar](https:\u002F\u002Fgithub.com\u002Fpaulmillr\u002Fchokidar).\n\n### Obtain Filesystem (Devices, Partitions) Information\n\n[fs-filesystem](https:\u002F\u002Fgithub.com\u002Farthurintelligence\u002Fnode-fs-filesystem) allows you to read the state of the filesystem of the host on which it is run. It returns information about both the devices and the partitions (volumes) of the system.\n\n### Misc.\n\n- [fs-extra-debug](https:\u002F\u002Fgithub.com\u002Fjdxcode\u002Ffs-extra-debug) - Send your fs-extra calls to [debug](https:\u002F\u002Fnpmjs.org\u002Fpackage\u002Fdebug).\n- [mfs](https:\u002F\u002Fgithub.com\u002Fcadorn\u002Fmfs) - Monitor your fs-extra calls.\n\n\n\nHacking on fs-extra\n-------------------\n\nWanna hack on `fs-extra`? Great! Your help is needed! [fs-extra is one of the most depended upon Node.js packages](http:\u002F\u002Fnodei.co\u002Fnpm\u002Ffs-extra.png?downloads=true&downloadRank=true&stars=true). This project\nuses [JavaScript Standard Style](https:\u002F\u002Fgithub.com\u002Ffeross\u002Fstandard) - if the name or style choices bother you,\nyou're gonna have to get over it :) If `standard` is good enough for `npm`, it's good enough for `fs-extra`.\n\n[![js-standard-style](https:\u002F\u002Fcdn.rawgit.com\u002Ffeross\u002Fstandard\u002Fmaster\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Ffeross\u002Fstandard)\n\nWhat's needed?\n- First, take a look at existing issues. Those are probably going to be where the priority lies.\n- More tests for edge cases. Specifically on different platforms. There can never be enough tests.\n- Improve test coverage.\n\nNote: If you make any big changes, **you should definitely file an issue for discussion first.**\n\n### Running the Test Suite\n\nfs-extra contains hundreds of tests.\n\n- `npm run lint`: runs the linter ([standard](http:\u002F\u002Fstandardjs.com\u002F))\n- `npm run unit`: runs the unit tests\n- `npm run unit-esm`: runs tests for `fs-extra\u002Fesm` exports\n- `npm test`: runs the linter and all tests\n\nWhen running unit tests, set the environment variable `CROSS_DEVICE_PATH` to the absolute path of an empty directory on another device (like a thumb drive) to enable cross-device move tests.\n\n\n### Windows\n\nIf you run the tests on the Windows and receive a lot of symbolic link `EPERM` permission errors, it's\nbecause on Windows you need elevated privilege to create symbolic links. You can add this to your Windows's\naccount by following the instructions here: http:\u002F\u002Fsuperuser.com\u002Fquestions\u002F104845\u002Fpermission-to-make-symbolic-links-in-windows-7\nHowever, I didn't have much luck doing this.\n\nSince I develop on Mac OS X, I use VMWare Fusion for Windows testing. I create a shared folder that I map to a drive on Windows.\nI open the `Node.js command prompt` and run as `Administrator`. I then map the network drive running the following command:\n\n    net use z: \"\\\\vmware-host\\Shared Folders\"\n\nI can then navigate to my `fs-extra` directory and run the tests.\n\n\nNaming\n------\n\nI put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:\n\n* https:\u002F\u002Fgithub.com\u002Fjprichardson\u002Fnode-fs-extra\u002Fissues\u002F2\n* https:\u002F\u002Fgithub.com\u002Fflatiron\u002Futile\u002Fissues\u002F11\n* https:\u002F\u002Fgithub.com\u002Fryanmcgrath\u002Fwrench-js\u002Fissues\u002F29\n* https:\u002F\u002Fgithub.com\u002Fsubstack\u002Fnode-mkdirp\u002Fissues\u002F17\n\nFirst, I believe that in as many cases as possible, the [Node.js naming schemes](http:\u002F\u002Fnodejs.org\u002Fapi\u002Ffs.html) should be chosen. However, there are problems with the Node.js own naming schemes.\n\nFor example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.\n\nWe have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?\n\nMy perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too.\n\nSo, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`.\n\n\nCredit\n------\n\n`fs-extra` wouldn't be possible without using the modules from the following authors:\n\n- [Isaac Shlueter](https:\u002F\u002Fgithub.com\u002Fisaacs)\n- [Charlie McConnel](https:\u002F\u002Fgithub.com\u002Favianflu)\n- [James Halliday](https:\u002F\u002Fgithub.com\u002Fsubstack)\n- [Andrew Kelley](https:\u002F\u002Fgithub.com\u002Fandrewrk)\n\n\n\n\nLicense\n-------\n\nLicensed under MIT\n\nCopyright (c) 2011-2024 [JP Richardson](https:\u002F\u002Fgithub.com\u002Fjprichardson)\n\n[1]: http:\u002F\u002Fnodejs.org\u002Fdocs\u002Flatest\u002Fapi\u002Ffs.html\n\n\n[jsonfile]: https:\u002F\u002Fgithub.com\u002Fjprichardson\u002Fnode-jsonfile\n","`fs-extra` 是一个为 Node.js 提供额外文件系统方法的库，如 copy()、remove() 和 mkdirs()。该项目基于原生 fs 模块进行了扩展，增加了对 Promise 的支持，并通过使用 `graceful-fs` 来避免 EMFILE 错误。它提供了更丰富的文件操作功能，包括目录创建、文件复制与删除等，同时保持了与原生 fs 模块的高度兼容性。适用于需要进行复杂文件系统操作但又希望代码简洁易维护的 Node.js 项目场景中，特别适合于自动化脚本编写或后端服务开发时处理文件系统相关的任务。",2,"2026-06-11 03:26:53","top_topic"]