Created
October 17, 2023 13:18
-
-
Save RahulBRB/5389917e7b071149639ca9548fcb1ce5 to your computer and use it in GitHub Desktop.
File system model for write, append, read, rename, unlink (delete). Commonly used features of the fs module include fs. readFile to read data from a file, fs. writeFile to write data to a file and replace the file if it already exists
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
let fs = require('fs') | |
//write file | |
fs.writeFile('myFile.txt','NodeJs code in code sample', function(){ | |
console.log('File Create') | |
}) | |
//append file | |
fs.appendFile('myCode.txt','My code append \n',function(){ | |
console.log('File Appended') | |
}) | |
//readFile | |
fs.readFile('myCode.txt','utf-8',function(err,data){ | |
if(err) throw err; | |
console.log(data) | |
}) | |
//renameFile | |
fs.rename('myCode.txt','myText.txt',function(err){ | |
if(err) throw err; | |
console.log('File Renamed') | |
}) | |
//unlink or Delete file | |
fs.unlink('myText.txt',function(err){ | |
if(err) throw err; | |
console.log('File Deleted') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment