node一些模块

2018-11-22  本文已影响0人  huanghaodong

child_process模块

const childProcess = require('child_process');

childProcess.exec('ls',function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    }else {
       
    }
});

path模块

const  join = require('path').join;

join('a','b'); //'a/b'

fs模块

const fs = require("fs");
let files = fs.readdirSync(目录名);

递归读取文件夹上传文件

let files = fs.readdirSync(readPath);
 files.forEach( function(file){
   let info = fs.statSync(readPath+"/"+file)
   if(info.isDirectory()){
     uploadDir(readPath + "/" + file);
   }else{
     const fullFile =  join(readPath,file)
  // toDo 上传文件
     uploadFile(' fullFile)
   }
 })

shelljs模块

const shell = require('shelljs');

 shell.rm("-rf",文件路径); //r表示递归删除所有文件,f表示强制删除

process.cwd()

上一篇下一篇

猜你喜欢

热点阅读