How to Write Data to a File in Node.js

In NodeJS, to write data to a file, you can use a quick and simple method in the “fs”┬ámodule.

How to write data to a File in Node.js

//load the fs module
var fs = require('fs');

fs.writeFile('/path/file.txt', "fileData", function (err) {
  if(!err) {
    console.log("file successfully saved.");
  } else {
    console.log("error", err);