process.cwd()和__dirname有什么区别? [英] What's the difference between process.cwd() vs __dirname?

查看:64
本文介绍了process.cwd()和__dirname有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别

console.log(process.cwd())

console.log(__dirname);

我已经看到两者都用在相似的上下文中.

I've seen both used in similar contexts.

推荐答案

返回当前工作目录,

即您从中调用node命令的目录.

i.e. the directory from which you invoked the node command.

__dirname 返回包含以下内容的目录的目录名称: JavaScript源代码文件

__dirname returns the directory name of the directory containing the JavaScript source code file

这篇关于process.cwd()和__dirname有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆