In Node using FileSystems, developer can perform the various file operations, create file, add content into file, delete file.
First import the FileSystems fs using the below node code
const fs = require('fs')
Then, using the Node FIleSystems object fs we could perform the form operations. Liek below.
fs.writeFileSync('notes.txt', 'This file is created by NodeJS application. ')
writeFileSync will create and write the first data into the file. writeFileSynch method have two parameters, first file name and second data.
Next if we want to add or append data into an existing file then use appendFileSync method. Like Below.
fs.appendFileSync('notes.txt', 'DO NOT DELETE THIS FILE')
No comments:
Post a Comment