Skip to content

Instantly share code, notes, and snippets.

@JimzyLui
Last active February 15, 2019 01:32
Show Gist options
  • Save JimzyLui/855edad38cd3f00e7cf5bddfac0c7d64 to your computer and use it in GitHub Desktop.
Save JimzyLui/855edad38cd3f00e7cf5bddfac0c7d64 to your computer and use it in GitHub Desktop.
### 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