Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: How to create file with 755 permissions with fs.createWriteStream

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

like image 825
cschuff Avatar asked Oct 04 '16 10:10

cschuff


1 Answers

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.

like image 150
Clarence Leung Avatar answered Oct 06 '22 01:10

Clarence Leung