Last active
February 15, 2019 01:32
-
-
Save JimzyLui/855edad38cd3f00e7cf5bddfac0c7d64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Include the module: | |
`const fs = require('fs');` | |
### Read File | |
`fs.readFile({fileName}, function(err, data){ | |
}` | |
### Create File (will append to file if already exists, else create) | |
```fs.appendFile({newFileName}, <strSomeContent>, function(err){ | |
if (err) throw err; | |
console.log('saved'); | |
});``` | |
### Open File | |
```fs.openFile({newFileName}, 'w', function(err, file){ | |
if (err) throw err; | |
console.log('saved'); | |
});``` | |
### Write File (will overwrite file if already exists, else create) | |
```fs.writeFile({newFileName}, <strSomeContent>, function(err){ | |
if (err) throw err; | |
console.log('saved'); | |
});``` | |
### Delete File | |
fs.unlink({fileName}, function (err) { | |
if (err) throw err; | |
console.log('File deleted!'); | |
}); | |
### Rename File | |
fs.rename({oldFileName}, {newFileName}, function (err) { | |
if (err) throw err; | |
console.log('File Renamed!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment