Random Notes‎ > ‎

node.js: Set unix socket permissions

posted Aug 25, 2010, 4:18 PM by William Shallum   [ updated Jul 5, 2015, 1:23 AM ]
Unix socket permissions depend on umask, so set umask before listen and reset it after listen succeeds (the callback parameter). The following code will do that.

var http = require("http");
var oldUmask = process.umask(0000);
var server = http.createServer(function(request, response) { 
  // ...

server.listen("/some/socket/path", function() {

If there is worry about what happens between the listen() succeeding and the callback being called, you can always set the permissions explicitly (not depending on umask) with a fs.chmodSync call when the listen succeeds.