Flag options of createWriteStream

Viewed 17118

I am using node js to write text file to disk :

const fs = Promise.promisifyAll(require('fs'));

var path = directory + '/cpu.log';

var a = fs.createWriteStream(path, {
            flags: 'a'
        });

a.write('test string');

What are the options for flags: 'foo'

I could not find the alternatives in documentation.

1 Answers

They are documented in fs.open https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback

For fs.createWriteStream of course you'll be interested in the flags for writing, such as w for write, a for append.

The docs hint that you can also use a number representing the flags from Linux Open(2). You can get a list of common ones with:

var fs = require('fs')
fs.constants
// { O_RDONLY: 0,
//   O_WRONLY: 1,
//   O_RDWR: 2,
//    ...

But you should probably stick with the normal r, w, a etc. unless you have a compelling reason not to.

Related