1 | # remove(path, [callback])
|
2 |
|
3 | Removes a file or directory. The directory can have contents. Like `rm -rf`.
|
4 |
|
5 | - `path` `<String>`
|
6 | - `callback` `<Function>`
|
7 |
|
8 | ## Example:
|
9 |
|
10 | ```js
|
11 | const fs = require('fs-extra')
|
12 |
|
13 | // remove file
|
14 | // With a callback:
|
15 | fs.remove('/tmp/myfile', err => {
|
16 | if (err) return console.error(err)
|
17 |
|
18 | console.log('success!')
|
19 | })
|
20 |
|
21 | fs.remove('/home/jprichardson', err => {
|
22 | if (err) return console.error(err)
|
23 |
|
24 | console.log('success!') // I just deleted my entire HOME directory.
|
25 | })
|
26 |
|
27 | // With Promises:
|
28 | fs.remove('/tmp/myfile')
|
29 | .then(() => {
|
30 | console.log('success!')
|
31 | })
|
32 | .catch(err => {
|
33 | console.error(err)
|
34 | })
|
35 |
|
36 | // With async/await:
|
37 | async function example (src, dest) {
|
38 | try {
|
39 | await fs.remove('/tmp/myfile')
|
40 | console.log('success!')
|
41 | } catch (err) {
|
42 | console.error(err)
|
43 | }
|
44 | }
|
45 |
|
46 | example()
|
47 | ```
|