Whisher Whisher - 5 months ago 32
Node.js Question

node how to create a directory if doesn't exist?

I'm wondering if this

var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
fs.mkdirSync(dir,0744);
}


is the right way to create a directory if not
exists with full permission for the script
and readable by others.

Answer
var fs = require('fs');
var dir = './tmp';

if (!fs.existsSync(dir)){
    fs.mkdirSync(dir);
}
Comments