Socket
Socket
Sign inDemoInstall

fs-extra

Package Overview
Dependencies
3
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.2 to 3.0.0

docs/pathExists-sync.md

63

CHANGELOG.md

@@ -0,1 +1,24 @@

3.0.0 / 2017-04-27
------------------
### Added
- **BREAKING:** Added Promise support. All asynchronous native fs methods and fs-extra methods now return a promise if the callback is not passed. [#403](https://github.com/jprichardson/node-fs-extra/pull/403)
- `pathExists()`, a replacement for the deprecated `fs.exists`. `pathExists` has a normal error-first callback signature. Also added `pathExistsSync`, an alias to `fs.existsSync`, for completeness. [#406](https://github.com/jprichardson/node-fs-extra/pull/406)
### Removed
- **BREAKING:** Removed support for setting the default spaces for `writeJson()`, `writeJsonSync()`, `outputJson()`, & `outputJsonSync()`. This was undocumented. [#402](https://github.com/jprichardson/node-fs-extra/pull/402)
### Changed
- Upgraded jsonfile dependency to v3.0.0:
- **BREAKING:** Changed behavior of `throws` option for `readJsonSync()`; now does not throw filesystem errors when `throws` is `false`.
- **BREAKING:** `writeJson()`, `writeJsonSync()`, `outputJson()`, & `outputJsonSync()` now output minified JSON by default for consistency with `JSON.stringify()`; set the `spaces` option to `2` to override this new behavior. [#402](https://github.com/jprichardson/node-fs-extra/pull/402)
- Use `Buffer.allocUnsafe()` instead of `new Buffer()` in environments that support it. [#394](https://github.com/jprichardson/node-fs-extra/pull/394)
### Fixed
- `removeSync()` silently failed on Windows in some cases. Now throws an `EBUSY` error. [#408](https://github.com/jprichardson/node-fs-extra/pull/408)
2.1.2 / 2017-03-16

@@ -221,6 +244,6 @@ ------------------

-------------------
- bugfix `fs.move()` into itself. Closes #104
- bugfix `fs.move()` moving directory across device. Closes #108
- bugfix `fs.move()` into itself. Closes [#104]
- bugfix `fs.move()` moving directory across device. Closes [#108]
- added coveralls support
- bugfix: nasty multiple callback `fs.copy()` bug. Closes #98
- bugfix: nasty multiple callback `fs.copy()` bug. Closes [#98]
- misc fs.copy code cleanups

@@ -262,3 +285,3 @@

* bugfix: upgaded `"jsonfile": "~1.1.0"` to `"jsonfile": "^1.2.0"`, bumped minor because of `jsonfile` dep change
from `~` to `^`. #67
from `~` to `^`. [#67]

@@ -271,7 +294,7 @@ 0.9.1 / 2014-05-22

------------------
* upgraded `ncp` from `~0.4.2` to `^0.5.1`, #58
* upgraded `ncp` from `~0.4.2` to `^0.5.1`, [#58]
* upgraded `rimraf` from `~2.2.6` to `^2.2.8`
* upgraded `mkdirp` from `0.3.x` to `^0.5.0`
* added methods `ensureFile()`, `ensureFileSync()`
* added methods `ensureDir()`, `ensureDirSync()` #31
* added methods `ensureDir()`, `ensureDirSync()` [#31]
* added `move()` method. From: https://github.com/andrewrk/node-mv

@@ -282,12 +305,12 @@

------------------
* copy failed to return an error to the callback if a file doesn't exist (ulikoehler #38, #39)
* copy failed to return an error to the callback if a file doesn't exist (ulikoehler [#38], [#39])
0.8.0 / 2013-10-14
------------------
* `filter` implemented on `copy()` and `copySync()`. (Srirangan / #36)
* `filter` implemented on `copy()` and `copySync()`. (Srirangan / [#36])
0.7.1 / 2013-10-12
------------------
* `copySync()` implemented (Srirangan / #33)
* updated to the latest `jsonfile` version `1.1.0` which gives `options` params for the JSON methods. Closes #32
* `copySync()` implemented (Srirangan / [#33])
* updated to the latest `jsonfile` version `1.1.0` which gives `options` params for the JSON methods. Closes [#32]

@@ -297,3 +320,3 @@ 0.7.0 / 2013-10-07

* update readme conventions
* `copy()` now works if destination directory does not exist. Closes #29
* `copy()` now works if destination directory does not exist. Closes [#29]

@@ -312,8 +335,8 @@ 0.6.4 / 2013-09-05

------------------
* added .npmignore, #25
* added .npmignore, [#25]
0.6.1 / 2013-05-14
------------------
* modified for `strict` mode, closes #24
* added `outputJson()/outputJsonSync()`, closes #23
* modified for `strict` mode, closes [#24]
* added `outputJson()/outputJsonSync()`, closes [#23]

@@ -325,3 +348,3 @@ 0.6.0 / 2013-03-18

* upgraded to latest `ncp` and `rimraf`.
* optional `graceful-fs` support. Closes #17
* optional `graceful-fs` support. Closes [#17]

@@ -364,3 +387,3 @@

* Rewrote module into JavaScript. (Must still rewrite tests into JavaScript)
* Added all methods of [jsonfile][https://github.com/jprichardson/node-jsonfile]
* Added all methods of [jsonfile](https://github.com/jprichardson/node-jsonfile)
* Added Travis-CI.

@@ -462,3 +485,3 @@

[#282]: https://github.com/jprichardson/node-fs-extra/pull/282 "Apply filter also on directories and symlinks for copySync()"
[#281]: https://github.com/jprichardson/node-fs-extra/issues/281 "remove function executes "successfully" but doesn't do anything?"
[#281]: https://github.com/jprichardson/node-fs-extra/issues/281 "remove function executes 'successfully' but doesn't do anything?"
[#280]: https://github.com/jprichardson/node-fs-extra/pull/280 "Disable rimraf globbing"

@@ -685,3 +708,3 @@ [#279]: https://github.com/jprichardson/node-fs-extra/issues/279 "Some code is vendored instead of included [awaiting-reply]"

[#60]: https://github.com/jprichardson/node-fs-extra/issues/60 "chmod & chown for mkdirs"
[#59]: https://github.com/jprichardson/node-fs-extra/issues/59 "Consider including mkdirp and making fs-extra "--use_strict" safe [question]"
[#59]: https://github.com/jprichardson/node-fs-extra/issues/59 "Consider including mkdirp and making fs-extra '--use_strict' safe [question]"
[#58]: https://github.com/jprichardson/node-fs-extra/issues/58 "Stack trace not included in fs.copy error"

@@ -698,3 +721,3 @@ [#57]: https://github.com/jprichardson/node-fs-extra/issues/57 "Possible to include wildcards in delete?"

[#48]: https://github.com/jprichardson/node-fs-extra/issues/48 "fs.copy issue [bug]"
[#47]: https://github.com/jprichardson/node-fs-extra/issues/47 "Bug in copy - callback called on readStream "close" - Fixed in ncp 0.5.0"
[#47]: https://github.com/jprichardson/node-fs-extra/issues/47 "Bug in copy - callback called on readStream 'close' - Fixed in ncp 0.5.0"
[#46]: https://github.com/jprichardson/node-fs-extra/pull/46 "update copyright year"

@@ -729,3 +752,3 @@ [#45]: https://github.com/jprichardson/node-fs-extra/pull/45 "Added note about fse.outputFile() being the one that overwrites"

[#18]: https://github.com/jprichardson/node-fs-extra/pull/18 "Exposed copyFile Function"
[#17]: https://github.com/jprichardson/node-fs-extra/issues/17 "Use `require("graceful-fs")` if found instead of `require("fs")`"
[#17]: https://github.com/jprichardson/node-fs-extra/issues/17 "Use `require('graceful-fs')` if found instead of `require('fs')`"
[#16]: https://github.com/jprichardson/node-fs-extra/pull/16 "Update README.md"

@@ -732,0 +755,0 @@ [#15]: https://github.com/jprichardson/node-fs-extra/issues/15 "Implement cp -r but sync aka copySync. [enhancement]"

@@ -1,2 +0,2 @@

# copy(src, dest, [options], callback)
# copy(src, dest, [options, callback])

@@ -31,2 +31,11 @@ Copy a file or directory. The directory can have contents. Like `cp -r`.

}) // copies directory, even if it has subdirectories or files
// Promise usage:
fs.copy('/tmp/myfile', '/tmp/mynewfile')
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -33,0 +42,0 @@

@@ -21,2 +21,11 @@ # emptyDir(dir, [callback])

})
// With promises
fs.emptyDir('/tmp/some/dir')
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# ensureDir(dir, callback)
# ensureDir(dir, [callback])

@@ -20,2 +20,11 @@ Ensures that the directory exists. If the directory structure does not exist, it is created. Like `mkdir -p`.

})
// With Promises:
fs.ensureDir(dir)
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# ensureFile(file, callback)
# ensureFile(file, [callback])

@@ -20,2 +20,11 @@ Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.

})
// With Promises:
fs.ensureFile(file)
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# ensureLink(srcpath, dstpath, callback)
# ensureLink(srcpath, dstpath, [callback])

@@ -20,2 +20,11 @@ Ensures that the link exists. If the directory structure does not exist, it is created.

})
// With Promises:
fs.ensureLink(srcpath, dstpath)
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# ensureSymlink(srcpath, dstpath, [type], callback)
# ensureSymlink(srcpath, dstpath, [type, callback])

@@ -21,2 +21,11 @@ Ensures that the symlink exists. If the directory structure does not exist, it is created.

})
// With Promises:
fs.ensureSymlink(srcpath, dstpath)
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# move(src, dest, [options], callback)
# move(src, dest, [options, callback])

@@ -21,2 +21,10 @@ Moves a file or directory, even across devices.

})
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -23,0 +31,0 @@

@@ -1,2 +0,2 @@

# outputFile(file, data, [options], callback)
# outputFile(file, data, [options, callback])

@@ -23,2 +23,12 @@ Almost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed). `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).

})
// With Promises:
fs.outputFile(file, 'hello!')
.then(() => fs.readFile(file, 'utf8'))
.then(data => {
console.log(data) // => hello!
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# outputJson(file, object, [options], callback)
# outputJson(file, object, [options, callback])

@@ -26,2 +26,12 @@ Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.

})
// With Promises:
fs.outputJson(file, {name: 'JP'})
.then(() => fs.readJson(file))
.then(data => {
console.log(data.name) // => JP
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# readJson(file, [options], callback)
# readJson(file, [options, callback])

@@ -19,5 +19,14 @@ Reads a JSON file and then parses it into an object. `options` are the same

if (err) console.error(err)
console.log(packageObj.version) // => 0.1.3
})
// Promise Usage
fs.readJson('./package.json')
.then(packageObj => {
console.log(packageObj.version) // => 0.1.3
})
.catch(err => {
// handle error
})
```

@@ -41,2 +50,11 @@

})
// Promise Usage
fs.readJson(file, { throws: false })
.then(obj => {
console.log(obj) // => null
})
.catch(err => {
// Not called
})
```

@@ -1,2 +0,2 @@

# remove(path, callback)
# remove(path, [callback])

@@ -25,2 +25,11 @@ Removes a file or directory. The directory can have contents. Like `rm -rf`.

})
// Promise Usage
fs.remove('/tmp/myfile')
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -1,2 +0,2 @@

# writeJson(file, object, [options], callback)
# writeJson(file, object, [options, callback])

@@ -23,2 +23,11 @@ Writes an object to a JSON file. `options` are the same that

})
// With Promises
fs.writeJson('./package.json', {name: 'fs-extra'})
.then(() => {
console.log('success!')
})
.catch(err => {
// handle error
})
```

@@ -25,0 +34,0 @@

@@ -6,3 +6,3 @@ 'use strict'

const BUF_LENGTH = 64 * 1024
const _buff = new Buffer(BUF_LENGTH)
const _buff = require('../util/buffer')(BUF_LENGTH)

@@ -9,0 +9,0 @@ function copyFileSync (srcFile, destFile, options) {

@@ -7,2 +7,3 @@ 'use strict'

const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

@@ -43,3 +44,4 @@ function copy (src, dest, options, callback) {

fs.exists(dir, dirExists => {
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return ncp(src, dest, options, callback)

@@ -46,0 +48,0 @@ mkdir.mkdirs(dir, err => {

@@ -0,3 +1,4 @@

const u = require('universalify').fromCallback
module.exports = {
copy: require('./copy')
copy: u(require('./copy'))
}
'use strict'
const u = require('universalify').fromCallback
const fs = require('fs')

@@ -8,3 +9,3 @@ const path = require('path')

function emptyDir (dir, callback) {
const emptyDir = u(function emptyDir (dir, callback) {
callback = callback || function () {}

@@ -27,3 +28,3 @@ fs.readdir(dir, (err, items) => {

})
}
})

@@ -30,0 +31,0 @@ function emptyDirSync (dir) {

'use strict'
const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

@@ -15,6 +17,8 @@ function createFile (file, callback) {

fs.exists(file, fileExists => {
pathExists(file, (err, fileExists) => {
if (err) return callback(err)
if (fileExists) return callback()
const dir = path.dirname(file)
fs.exists(dir, dirExists => {
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return makeFile()

@@ -41,7 +45,4 @@ mkdir.mkdirs(dir, err => {

module.exports = {
createFile,
createFileSync,
// alias
ensureFile: createFile,
ensureFileSync: createFileSync
createFile: u(createFile),
createFileSync
}
'use strict'
const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

@@ -15,3 +17,4 @@ function createLink (srcpath, dstpath, callback) {

fs.exists(dstpath, destinationExists => {
pathExists(dstpath, (err, destinationExists) => {
if (err) return callback(err)
if (destinationExists) return callback(null)

@@ -25,3 +28,4 @@ fs.lstat(srcpath, (err, stat) => {

const dir = path.dirname(dstpath)
fs.exists(dir, dirExists => {
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return makeLink(srcpath, dstpath)

@@ -57,7 +61,4 @@ mkdir.mkdirs(dir, err => {

module.exports = {
createLink,
createLinkSync,
// alias
ensureLink: createLink,
ensureLinkSync: createLinkSync
createLink: u(createLink),
createLinkSync
}

@@ -5,2 +5,3 @@ 'use strict'

const fs = require('graceful-fs')
const pathExists = require('../path-exists').pathExists

@@ -44,3 +45,4 @@ /**

const relativeToDst = path.join(dstdir, srcpath)
return fs.exists(relativeToDst, exists => {
return pathExists(relativeToDst, (err, exists) => {
if (err) return callback(err)
if (exists) {

@@ -47,0 +49,0 @@ return callback(null, {

'use strict'
const u = require('universalify').fromCallback
const path = require('path')

@@ -17,2 +18,4 @@ const fs = require('graceful-fs')

const pathExists = require('../path-exists').pathExists
function createSymlink (srcpath, dstpath, type, callback) {

@@ -22,3 +25,4 @@ callback = (typeof type === 'function') ? type : callback

fs.exists(dstpath, destinationExists => {
pathExists(dstpath, (err, destinationExists) => {
if (err) return callback(err)
if (destinationExists) return callback(null)

@@ -31,3 +35,4 @@ symlinkPaths(srcpath, dstpath, (err, relative) => {

const dir = path.dirname(dstpath)
fs.exists(dir, dirExists => {
pathExists(dir, (err, dirExists) => {
if (err) return callback(err)
if (dirExists) return fs.symlink(srcpath, dstpath, type, callback)

@@ -62,7 +67,4 @@ mkdirs(dir, err => {

module.exports = {
createSymlink,
createSymlinkSync,
// alias
ensureSymlink: createSymlink,
ensureSymlinkSync: createSymlinkSync
createSymlink: u(createSymlink),
createSymlinkSync
}

@@ -5,12 +5,7 @@ 'use strict'

const fse = {}
const gfs = require('graceful-fs')
const fs = {}
// attach fs methods to fse
Object.keys(gfs).forEach(key => {
fse[key] = gfs[key]
})
const fs = fse
// Export graceful-fs:
assign(fs, require('./fs'))
// Export extra methods:
assign(fs, require('./copy'))

@@ -26,14 +21,4 @@ assign(fs, require('./copy-sync'))

assign(fs, require('./output'))
assign(fs, require('./path-exists'))
module.exports = fs
// maintain backwards compatibility for awhile
const jsonfile = {}
Object.defineProperty(jsonfile, 'spaces', {
get: () => fs.spaces, // found in ./json
set: val => {
fs.spaces = val
}
})
module.exports.jsonfile = jsonfile // so users of fs-extra can modify jsonFile.spaces
'use strict'
const u = require('universalify').fromCallback
const jsonFile = require('./jsonfile')
jsonFile.outputJsonSync = require('./output-json-sync')
jsonFile.outputJson = require('./output-json')
jsonFile.outputJson = u(require('./output-json'))
// aliases
jsonFile.outputJSONSync = require('./output-json-sync')
jsonFile.outputJSON = require('./output-json')
jsonFile.outputJSONSync = jsonFile.outputJSONSync
jsonFile.outputJSON = jsonFile.outputJson
jsonFile.writeJSON = jsonFile.writeJson
jsonFile.writeJSONSync = jsonFile.writeJsonSync
jsonFile.readJSON = jsonFile.readJson
jsonFile.readJSONSync = jsonFile.readJsonSync
module.exports = jsonFile
'use strict'
const u = require('universalify').fromCallback
const jsonFile = require('jsonfile')

@@ -7,11 +8,6 @@

// jsonfile exports
readJson: jsonFile.readFile,
readJSON: jsonFile.readFile,
readJson: u(jsonFile.readFile),
readJsonSync: jsonFile.readFileSync,
readJSONSync: jsonFile.readFileSync,
writeJson: jsonFile.writeFile,
writeJSON: jsonFile.writeFile,
writeJsonSync: jsonFile.writeFileSync,
writeJSONSync: jsonFile.writeFileSync,
spaces: 2 // default in fs-extra
writeJson: u(jsonFile.writeFile),
writeJsonSync: jsonFile.writeFileSync
}
'use strict'
const fs = require('graceful-fs')
const path = require('path')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists
const jsonFile = require('./jsonfile')

@@ -16,3 +16,4 @@

fs.exists(dir, itDoes => {
pathExists(dir, (err, itDoes) => {
if (err) return callback(err)
if (itDoes) return jsonFile.writeJson(file, data, options, callback)

@@ -19,0 +20,0 @@

@@ -0,9 +1,14 @@

'use strict'
const u = require('universalify').fromCallback
const mkdirs = u(require('./mkdirs'))
const mkdirsSync = require('./mkdirs-sync')
module.exports = {
mkdirs: require('./mkdirs'),
mkdirsSync: require('./mkdirs-sync'),
mkdirs: mkdirs,
mkdirsSync: mkdirsSync,
// alias
mkdirp: require('./mkdirs'),
mkdirpSync: require('./mkdirs-sync'),
ensureDir: require('./mkdirs'),
ensureDirSync: require('./mkdirs-sync')
mkdirp: mkdirs,
mkdirpSync: mkdirsSync,
ensureDir: mkdirs,
ensureDirSync: mkdirsSync
}

@@ -8,2 +8,3 @@ 'use strict'

const mkdirpSync = require('../mkdirs').mkdirsSync
const buffer = require('../util/buffer')

@@ -64,3 +65,3 @@ function moveSync (src, dest, options) {

const BUF_LENGTH = 64 * 1024
const _buff = new Buffer(BUF_LENGTH)
const _buff = buffer(BUF_LENGTH)

@@ -67,0 +68,0 @@ const flags = overwrite ? 'w' : 'wx'

@@ -9,2 +9,3 @@ 'use strict'

const u = require('universalify').fromCallback
const fs = require('graceful-fs')

@@ -161,3 +162,3 @@ const ncp = require('../copy/ncp')

module.exports = {
move
move: u(move)
}
'use strict'
const u = require('universalify').fromCallback
const fs = require('graceful-fs')
const path = require('path')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

@@ -14,3 +16,4 @@ function outputFile (file, data, encoding, callback) {

const dir = path.dirname(file)
fs.exists(dir, itDoes => {
pathExists(dir, (err, itDoes) => {
if (err) return callback(err)
if (itDoes) return fs.writeFile(file, data, encoding, callback)

@@ -36,4 +39,4 @@

module.exports = {
outputFile,
outputFile: u(outputFile),
outputFileSync
}
'use strict'
const u = require('universalify').fromCallback
const rimraf = require('./rimraf')
function removeSync (dir) {
return rimraf.sync(dir, {disableGlob: true})
}
function remove (dir, callback) {
const options = {disableGlob: true}
return callback ? rimraf(dir, options, callback) : rimraf(dir, options, function () {})
}
module.exports = {
remove,
removeSync
remove: u(rimraf),
removeSync: rimraf.sync
}

@@ -278,8 +278,8 @@ 'use strict'

} catch (er) {
if (er.code === 'ENOENT') {
return
} else if (er.code === 'ENOTDIR') {
if (er.code === 'ENOTDIR') {
throw originalEr
} else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') {
rmkidsSync(p, options)
} else if (er.code !== 'ENOENT') {
throw er
}

@@ -286,0 +286,0 @@ }

{
"name": "fs-extra",
"version": "2.1.2",
"version": "3.0.0",
"description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.",

@@ -37,3 +37,4 @@ "homepage": "https://github.com/jprichardson/node-fs-extra",

"graceful-fs": "^4.1.2",
"jsonfile": "^2.1.0"
"jsonfile": "^3.0.0",
"universalify": "^0.1.0"
},

@@ -51,3 +52,3 @@ "devDependencies": {

"secure-random": "^1.1.1",
"standard": "^8.5.0"
"standard": "^10.0.2"
},

@@ -54,0 +55,0 @@ "main": "./lib/index",

Node.js: fs-extra
=================
`fs-extra` adds file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`.
`fs-extra` adds file system methods that aren't included in the native `fs` module and adds promise support to the `fs` methods. It should be a drop in replacement for `fs`.

@@ -33,3 +33,3 @@ [![npm Package](https://img.shields.io/npm/v/fs-extra.svg?style=flat-square)](https://www.npmjs.org/package/fs-extra)

`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are unmodified and attached to `fs-extra`.
`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.

@@ -64,3 +64,3 @@ You don't ever need to include the original `fs` module again:

-------------
Most methods are async by default (they take a callback with an `Error` as first argument).
Most methods are async by default. All async methods will return a promise if the callback isn't passed.

@@ -74,10 +74,19 @@ Sync methods on the other hand will throw if an error occurs.

// Async with promises:
fs.copy('/tmp/myfile', '/tmp/mynewfile')
.then(() => console.log('success!'))
.catch(err => {
// Handle error
})
// Async with callbacks:
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
if (err) return console.error(err)
console.log("success!")
});
console.log('success!')
})
// Sync:
try {
fs.copySync('/tmp/myfile', '/tmp/mynewfile')
console.log("success!")
console.log('success!')
} catch (err) {

@@ -104,2 +113,3 @@ console.error(err)

- [outputJson](docs/outputJson.md)
- [pathExists](docs/pathExists.md)
- [readJson](docs/readJson.md)

@@ -121,2 +131,3 @@ - [remove](docs/remove.md)

- [outputJsonSync](docs/outputJson-sync.md)
- [pathExistsSync](docs/pathExists-sync.md)
- [readJsonSync](docs/readJson-sync.md)

@@ -127,3 +138,3 @@ - [removeSync](docs/remove-sync.md)

**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.
**NOTE:** You can still use the native Node.js methods. They are promisified and copied over to `fs-extra`.

@@ -138,21 +149,3 @@ ### What happened to `walk()` and `walkSync()`?

### Promises
Use [Bluebird](https://github.com/petkaantonov/bluebird). See https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification. `fs-extra` is
explicitly listed as supported.
```js
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
```
Or you can use a dedicated package:
- [`fs-extra-promise`](https://github.com/overlookmotel/fs-extra-promise) uses Bluebird.
- [`fs-promise`](https://github.com/kevinbeaty/fs-promise) uses
[Any Promise](https://github.com/kevinbeaty/any-promise) and also covers
[`mz/fs`](https://github.com/normalize/mz/blob/master/fs.js).
- [`fs-p`](https://github.com/grammarly/fs-p) - TypeScript-friendly promises implementation
### TypeScript

@@ -159,0 +152,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc