如果目录不存在,这是创建目录的正确方法吗?它应该对该脚本具有完全的权限,并且可以被其他人读取。
var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}
如果目录不存在,这是创建目录的正确方法吗?它应该对该脚本具有完全的权限,并且可以被其他人读取。
var dir = __dirname + '/upload';
if (!path.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}
The best solution would be to use the npm module called node-fs-extra. It has a method called
mkdir
which creates the directory you mentioned. If you give a long directory path, it will create the parent folders automatically. The module is a super set of npm modulefs
, so you can use all the functions infs
also if you add this module.