Instructions for the fs.createWriteStream method in node.js

  • 2020-05-07 19:12:50
  • OfStack

method description:

Returns an WriteStream (output stream) object (writable stream).

syntax:


fs.createWriteStream(path, [options])

Since this method belongs to the fs module, the fs module (var fs= require(" fs ")) needs to be introduced before use.

receive parameter:

path       file path

The option (object) parameter contains the following properties:


{ flags: 'w',
 
  encoding: null,
 
  mode: 0666 }

option includes a boot option to allow data to be written at the beginning of some files.

The default value of flags is w. If you want to modify 1 file instead of replacing it, you need to change flags to R +.

example:


fs.createWriteStream = function(path, options) {
 
  return new WriteStream(path, options);
 
};


Related articles: