我正在编写我自己的CLI节点模块'npak‘,这个模块是全局安装的。
我需要找到执行(全局) cli命令的项目的本地'node_modules‘文件夹的绝对路径。
假设该项目如下所示:
/home
/projects
/test-project/
/package.json
/node-modules
/folder-one
/folder-two
/folder-three/ npak find-modules
^-- this should return absolute path of node-modules folder应该返回:/home/projects/test-project/node-modules,即使npak是全局安装的
如何获得本地“节点-模块”文件夹的绝对路径,而不管cwd是从全局安装的包中得到什么?
发布于 2016-09-17 15:06:04
有一些有用的模块,比如find-node-modules,可以帮助您完成这样的任务。
发布于 2016-09-17 05:23:22
__dirname给出了执行脚本的路径。
https://stackoverflow.com/questions/39542206
复制相似问题