且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用npm在当前目录中安装package.json依赖项

更新时间:2022-06-12 22:20:58

运行:

npm install

从您的应用程序目录(即package.json所在的位置)将安装应用程序的依赖关系,而不是将其作为模块安装如这里所述。这些将放在./node_modules相对于你的package.json文件(实际上比这更复杂一些,所以检查 npm文档在这里)。

from inside your app directory (i.e. where package.json is located) will install the dependencies for your app, rather than install it as a module, as described here. These will be placed in ./node_modules relative to your package.json file (it's actually slightly more complex than this, so check the npm docs here).

如果需要,可以将node_modules目录移动到应用程序的父目录,因为节点的需要机制明白这一点但是,如果要使用install / update更新应用程序的依赖项,npm将不会再看到重定位的node_modules,而是相对于package.json再次创建一个新的目录。

You are free to move the node_modules dir to the parent dir of your app if you want, because node's 'require' mechanism understands this. However, if you want to update your app's dependencies with install/update, npm will not see the relocated 'node_modules' and will instead create a new dir, again relative to package.json.

为了防止这种情况,只需从应用程序目录创建一个重新定位的node_modules的符号链接:

To prevent this, just create a symlink to the relocated node_modules from your app dir:

ln -s ../node_modules node_modules