1,拼接路径
const fs = require('fs') const path = require('path') fs.readFile(path.join(__dirname,'path'),'utf8',function(err,dataStr){ if(err){ return console.log(err.message) } console.log(err.message) })
2,获取路径文件名
const fs = require('fs') const path = require('path') //定义文件存放路径
const fpath = path.basename('path')
const name = path.basename(fpath,'.html')
console.log(name)
const fext = path.extname(fpath)
console.log(fext)//输出扩展名
标签:fs,const,log,err,模块化,文件系统,console,path From: https://www.cnblogs.com/wencaiguagua/p/16804715.html