8

Which flag do I need to use in Nodes fs.createWriteStream to make it create files with 755 permissions.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
cschuff
  • 5,502
  • 7
  • 36
  • 52
  • https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options You can follow this link and you will get all the information – Himanshu Goyal Oct 04 '16 at 10:46

1 Answers1

19

You can set permissions with createWriteStream, using the mode option:

var fs = require('fs');

var stream = fs.createWriteStream('hello.js', { mode: 0o755 });
stream.write("#!/usr/bin/node\n");
stream.write("console.log('hello world');");
stream.end();

This will create a file called hello.js with the mode set to 755 permissions.

Clarence Leung
  • 2,446
  • 21
  • 24
  • 2
    It's correct, `mode` takes in a number, and in this case, I'm using an octal number for permissions, since that's how permissions like 755 are usually represented in UNIX. https://en.wikipedia.org/wiki/Chmod#Octal_modes – Clarence Leung Oct 04 '16 at 10:52
  • Ahh, I was unaware that `0o644` is a valid octal notation. Carry on. :) – Tomalak Oct 04 '16 at 10:54