3) Create a new text file from Node.js
var fs = require ('fs'); // include pre-built node file stream module
var data = "Creating a new file";
fs.writeFile('newFile.txt', data, function (err){
if (err) throw err;
console.log (" File created successfully"};
});
Run the program in the terminal:
$ node createNewFile.js
File created successfully
No comments:
Post a Comment