You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+16-25
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Node.js: fs-extra
2
2
=================
3
3
4
-
`fs-extra` adds file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`.
4
+
`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`.
`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are unmodified and attached to `fs-extra`.
33
+
`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.
34
34
35
35
You don't ever need to include the original `fs` module again:
36
36
@@ -60,7 +60,7 @@ const fse = require('fs-extra')
60
60
61
61
Sync vs Async
62
62
-------------
63
-
Most methods are async by default (they take a callback with an `Error` as first argument).
63
+
Most methods are async by default. All async methods will return a promise if the callback isn't passed.
64
64
65
65
Sync methods on the other hand will throw if an error occurs.
66
66
@@ -69,14 +69,23 @@ Example:
69
69
```js
70
70
constfs=require('fs-extra')
71
71
72
+
// Async with promises:
73
+
fs.copy('/tmp/myfile', '/tmp/mynewfile')
74
+
.then(() =>console.log('success!'))
75
+
.catch(err=> {
76
+
// Handle error
77
+
})
78
+
79
+
// Async with callbacks:
72
80
fs.copy('/tmp/myfile', '/tmp/mynewfile', err=> {
73
81
if (err) returnconsole.error(err)
74
-
console.log("success!")
75
-
});
82
+
console.log('success!')
83
+
})
76
84
85
+
// Sync:
77
86
try {
78
87
fs.copySync('/tmp/myfile', '/tmp/mynewfile')
79
-
console.log("success!")
88
+
console.log('success!')
80
89
} catch (err) {
81
90
console.error(err)
82
91
}
@@ -119,7 +128,7 @@ Methods
119
128
-[writeJsonSync](docs/writeJson-sync.md)
120
129
121
130
122
-
**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.
131
+
**NOTE:** You can still use the native Node.js methods. They are promisified and copied over to `fs-extra`.
123
132
124
133
### What happened to `walk()` and `walkSync()`?
125
134
@@ -129,24 +138,6 @@ They were removed from `fs-extra` in v2.0.0. If you need the functionality, `wal
129
138
Third Party
130
139
-----------
131
140
132
-
### Promises
133
-
134
-
Use [Bluebird](https://github.com/petkaantonov/bluebird). See https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification. `fs-extra` is
0 commit comments