How to create a directory if it doesn't exist using Node.js?

前端 未结 18 1140
臣服心动
臣服心动 2020-11-30 16:03

Is this the right way to create a directory if it doesn\'t exist. It should have full permission for the script and readable by others.

var dir = __dirname +         


        
18条回答
  •  情歌与酒
    2020-11-30 16:50

    Just in case any one interested in the one line version. :)

    //or in typescript: import * as fs from 'fs';
    const fs = require('fs');
    !fs.existsSync(dir) && fs.mkdirSync(dir);
    

提交回复
热议问题