What are the npm equivalent of:
npm相当于什么?
pip freeze > requirements.txt
pip install -r requirements.txt
3 个解决方案
#1
6
Normally dependencies in a node project are installed via package.json: https://docs.npmjs.com/files/package.json
节点项目中的依赖关系通常是通过包安装的。json:https://docs.npmjs.com/files/package.json
You install each dependency with npm install --save my-dependency
and it will be added to the package.json file. So the next person on the project can install all the dependencies with npm install
command on the same folder of package.json.
您可以安装npm安装的每个依赖项——保存依赖项,并将它添加到包中。json文件。因此,项目的下一个人可以在package.json的同一文件夹中安装所有与npm安装命令的依赖关系。
But in my case i wanted to install global requirements of npm via a text file (similar to pip install -r requirements.txt
).
但在我的例子中,我想通过一个文本文件(类似于pip安装-r requirements.txt)来安装npm的全局需求。
You can do that with:
你可以这样做:
cat requirements.txt | xargs npm install -g
猫的要求。txt | xargs npm安装-g。
#2
9
You might want to take a look at the documentation for npm shrinkwrap. It creates an npm-shrinkwrap.json
, which will take precedence over any package.json
when installing.
您可能想看看npm shrinkwrap的文档。它创建一个npm-shrinkwrap。json将优先于任何包。json在安装。
Basically, the equivalent is:
基本上,相当于:
npm shrinkwrap
npm install
Edit:
编辑:
Since v5.0.0, npm now always creates a package-lock.json
, with the same format as npm-shrinkwrap.json
. There have been other changes since then, not least in the latest v5.6.0. See the package-lock docs.
由于v5.0.0, npm现在总是创建一个包锁。json格式与npm-shrinkwrap.json格式相同。从那以后,还有其他的变化,尤其是在最新的v5.6.0中。看到package-lock文档。
#3
1
To install npm packages globally from a text file (e.g. npm-requirements.txt
) with a format similar to a pip requirement file:
从文本文件(例如npm-requirements.txt)在全局上安装npm包,格式类似于pip需求文件:
sed 's/#.*//' npm-requirements.txt | xargs npm install -g
This allows comments in the requirements file, just like pip. (source)
这允许需求文件中的注释,就像pip一样。(源)
A command similar to pip freeze > requirements.txt
is:
一个类似于pip冻结>要求的命令。三是:
ls "$(npm root -g)" > npm-requirements.txt
However, this is imperfect because it does not save the version numbers of npm packages.
但是,这并不完美,因为它没有保存npm包的版本号。
#1
6
Normally dependencies in a node project are installed via package.json: https://docs.npmjs.com/files/package.json
节点项目中的依赖关系通常是通过包安装的。json:https://docs.npmjs.com/files/package.json
You install each dependency with npm install --save my-dependency
and it will be added to the package.json file. So the next person on the project can install all the dependencies with npm install
command on the same folder of package.json.
您可以安装npm安装的每个依赖项——保存依赖项,并将它添加到包中。json文件。因此,项目的下一个人可以在package.json的同一文件夹中安装所有与npm安装命令的依赖关系。
But in my case i wanted to install global requirements of npm via a text file (similar to pip install -r requirements.txt
).
但在我的例子中,我想通过一个文本文件(类似于pip安装-r requirements.txt)来安装npm的全局需求。
You can do that with:
你可以这样做:
cat requirements.txt | xargs npm install -g
猫的要求。txt | xargs npm安装-g。
#2
9
You might want to take a look at the documentation for npm shrinkwrap. It creates an npm-shrinkwrap.json
, which will take precedence over any package.json
when installing.
您可能想看看npm shrinkwrap的文档。它创建一个npm-shrinkwrap。json将优先于任何包。json在安装。
Basically, the equivalent is:
基本上,相当于:
npm shrinkwrap
npm install
Edit:
编辑:
Since v5.0.0, npm now always creates a package-lock.json
, with the same format as npm-shrinkwrap.json
. There have been other changes since then, not least in the latest v5.6.0. See the package-lock docs.
由于v5.0.0, npm现在总是创建一个包锁。json格式与npm-shrinkwrap.json格式相同。从那以后,还有其他的变化,尤其是在最新的v5.6.0中。看到package-lock文档。
#3
1
To install npm packages globally from a text file (e.g. npm-requirements.txt
) with a format similar to a pip requirement file:
从文本文件(例如npm-requirements.txt)在全局上安装npm包,格式类似于pip需求文件:
sed 's/#.*//' npm-requirements.txt | xargs npm install -g
This allows comments in the requirements file, just like pip. (source)
这允许需求文件中的注释,就像pip一样。(源)
A command similar to pip freeze > requirements.txt
is:
一个类似于pip冻结>要求的命令。三是:
ls "$(npm root -g)" > npm-requirements.txt
However, this is imperfect because it does not save the version numbers of npm packages.
但是,这并不完美,因为它没有保存npm包的版本号。