当前位置:网站首页>nodejs 中 path.join() 和 path.resolve()的区别
nodejs 中 path.join() 和 path.resolve()的区别
2022-06-22 10:14:00 【zh阿飞】
nodejs 中 path.join() 和 path.resolve()
基本介绍
__dirname:返回当前文件所在的绝对路径
引入 path模块
const path = require('path')
使用

path.join()
path.join() 主要作用是拼接路径
path.join方法用于连接路径。该方法的主要用途在于,会正确使用当前系统的路径分隔符,Unix系统是”/“,Windows系统是”\“。
console.log(path.join('a', 'b', '..', 'c/', './d'));
// 将path片段都连接起来
// 输出:a/c/d
path.resolve()
path.resolve() 方法用于将相对路径转为绝对路径。
/作为绝对路径的根目录,遇到 / 则回到根目录解析
它可以接受多个参数,依次表示所要进入的路径,直到将最后一个参数转为绝对路径。如果根据参数无法得到绝对路径,就以当前所在路径作为基准。除了根目录,该方法的返回值都不带尾部的斜杠
path.resolve(); // 默认返回所在目录绝对路径,等于 __dirname
path.resolve('/foo/bar', './baz')
// '/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// '/tmp/file'
执行的效果类似于 cd 操作
cd /foo/bar ==> /foo/bar
cd ./baz ==> /foo/bar
cd /tmp/file ==> /tmp/file
边栏推荐
- 6-40 constructing ordered sparse polynomial chained storage
- Qt编写物联网管理平台36-通信协议
- AttributeError: module ‘skimage. draw‘ has no attribute ‘circle‘
- How to transfer the values in the database to JSP pages through servlets and display them in El expressions?
- It was exposed that more than 170million pieces of private data had been leaked, and Xuetong responded that no clear evidence had been found
- 字节三面:到底知不知道什么是Eureka?
- Opencv人脸识别之发送QQ邮箱
- From in MySQL_ Unixtime and UNIX_ Timestamp processing database timestamp conversion - Case
- 一条TCP连接时占用内存空间多少?
- Catch up with this big guy
猜你喜欢

加密市场暴跌,stETH引发新一轮担忧

It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines

Ctfshow web realizes killing through one question

Summary and Prospect of AI security technology | community essay solicitation

AttributeError: module ‘skimage. draw‘ has no attribute ‘circle‘

Quickly master asp Net authentication framework identity - login and logout

Vs2022 connecting to SQLSERVER database tutorial

Open a safe distance: the international space station has taken measures to actively avoid space debris

xlrd.biffh.XLRDError: Excel xlsx file; not supported 解决办法

Bloom filter optimization - crimsondb series of papers (I)
随机推荐
6-32 construction of linked list by header insertion method
How harmful is the code signature certificate once it is leaked
[机缘参悟-28]:鬼谷子-内揵篇-保全自己,说服上司
呼叫中心CTI系统
Summary of neural network training trick
px4代码学习之基于uavcan协议的时间同步消息中添加自定义字段
6-40 constructing ordered sparse polynomial chained storage
JG_fx_20220620
TikTok 宣布将数据存储于 Oracle 服务器!
Don't be silly enough to distinguish hash, chunkhash and contenthash
QT compile the Internet of things management platform 36- communication protocol
Three months to successfully "turn over" the software project!
TCP 拥塞识别
CISP教材更新:2019年八大知识域新知识体系介绍
Some penetration test terms I collected
7-1 group minimum
DAO 的未来:构建 web3 的组织原语
The future of Dao: an organization primitive for building Web3
Pareto's law at work: focus on results, not outputs
2022-06-09 工作记录--yarn/npm-Error-EPERM: operation not permitted, uv_cwd