如果使用Node.js不存在目录,如何创建目录?

Node.js

Eva飞云

2020-03-16

如果目录不存在,这是创建目录的正确方法吗?它应该对该脚本具有完全的权限,并且可以被其他人读取。

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

第1696篇《如果使用Node.js不存在目录,如何创建目录?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
乐泡芙 2020.03.16

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 module fs, so you can use all the functions in fs also if you add this module.

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android