node中常用模块方法
1. fs模块:
2. url模块:
2.1: url.parse()
// 接受两个入参, 第一个是请求url, 第二个参数如果为true那么会将处理后的地址对象中的query属性变为一个对象,以此方便取参
let url = url.parse(request.url, true);
console.log(url)
打印得出:
Url { protocol: null, slashes: null, auth: null, host: null, port: null, hostname: null, hash: null, search: '?age=78', query: [Object: null prototype] { age: '78' }, pathname: '/', path: '/?age=78', href: '/?age=78' }
3. path模块
3.1 path.resolve
// __dirname:当前文件所在的绝对路径, path.resolve直接拼入参路径, '..'在resolve中表示返回上一级 // console.log(path.resolve(__dirname, '..', '..'))

浙公网安备 33010602011771号