1、process
process.cwd()获取当前文件所在路径
console.log(process.cwd());//C:\Users\chengdong\Documents\vs\Node\fs模块
process.env 获取当前应用所在的环境
console.log(process.env);
console.log(process.execPath);
process.execPath 获取执行文件所在的执行环境
2、path
path模块是node.js自带的模块,主要是为了解决服务器端路径问题而诞生的
const path = require("path")
console.log(__dirname);获取当前文件所在路径
2-1 basename
c:/data/logo.jpg
# logo.jpg
path.basename('c:/data/logo.jpg')
2-2 join-resolve
var s = path.join(__dirname,"static")
console.log(s);
var t = path.resolve(__dirname,"static")
console.log(t);
2-3 extname 获取文件扩展名
console.log(path.extname(process.execPath))
3、static
读取静态资源
yarn add koa-static
const koa = require("koa");
const app = new koa();
const path = require("path");
const static = require("koa-static");
app.use(static(path.join(__dirname,"static")))
app.listen(8000);