open() function is used to opens a file by passing a file name.

Syntax :, flags[mode], callback)


  • path : It is a string having file name with complete path
  • flags : It indicates the behavior of the file to be opened
  • mode : It sets the file mode like permission
  • callback : gets two arguments (err, fd)
BY Best Interview Question ON 12 Jun 2020


var fs = require("fs");

// Asynchronous - Open a File
console.log("open file");'file.txt', 'r+', function(err, fd) {
   if (err) {
      return console.error(err);
   console.log("File opened");