path.resolve(process.cwd()):
当前执行node命令所在的文件夹地址。即,在哪里调用node命令,得到的就是哪个地址。
path.resolve(__dirname):
被执行的js文件所在的文件夹地址。
栗子:
/Users/sherry/Section-Code/myProjects-Practices/yeoman-generator/generator-flash/project
下有个index.js文件,index.js里面console.log()了path.resolve(process.cwd())和path.resolve(__dirname)。
在/Users/sherry/Section-Code/myProjects-Practices/yeoman-generator/test目录下,执行:
node index.js
【结果】
process.cwd() === '/Users/sherry/Section-Code/myProjects-Practices/yeoman-generator/test'
path.resolve(__dirname) === '/Users/sherry/Section-Code/myProjects-Practices/yeoman-generator/generator-flash/project'
网友评论