path.resolve和path.join

1、path.resolve(ag1,ag2,...)

path.resolve返回当前环境所在路径拼接参数字符串所得到的绝对路径,其中参数可以有多个

const path = require('path');

path.resolve('/foo/bar', './baz')
// returns '/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/')
// returns '/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'

2、path.join(ag1,ag2,...)

const path=require('path');

path.join('a','b');
//返回 a\b

path.join(__dirname,'c','main.js')
//返回 D:\c\main.js  ,__dirname表示当前运行环境绝对路径

//path.join()方法拼接路径,并返回该路径,结合__dirname可以达到path.resolve()方法同样的效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值