yky-iris

Nodejs中process.cwd()与__dirname的区别

首先,上官方解释。

=> process.cwd(): The process.cwd() method returns the current working directory of theNode.js process.

上面的意思就是,process.cwd()返回的是当前Node.js进程执行时的工作目录。

直观一点,看下图

 

 

图中可见,sand文件夹下有一个file文件夹,这时,当我们在sand文件夹下执行

node ./file/1.js

显而易见,打出来的是运行node进程的目录。

而__dirname,上官方解释

=> __dirname: 当前模块的目录名。

什么意思呢?就是指当前执行的js的目录名,执行在sand文件夹下执行node ./file/1.js

可见,它直接到了1.js所在的文件夹,file下。

ok,这就上上面两者的区别了。

 

posted on 2018-03-21 16:20 北辰狼月 阅读(...) 评论(...) 编辑 收藏

分类:

技术点:

相关文章:

  • 2021-09-29
  • 2019-10-30
  • 2021-11-06
  • 2021-09-29
  • 2019-12-18
  • 2021-10-24
  • 2021-09-21
  • 2021-10-29
猜你喜欢
  • 2018-12-12
  • 2021-07-02
  • 2022-01-09
  • 2021-05-22
  • 2021-05-25
  • 2021-11-02
  • 2021-11-17
相关资源
相似解决方案