I have the following directory structure:
我有以下目录结构:
/some_project
source.js
package.json
I would like to install the dependencies for some_project. I know I could cd into some_project and then run npm install
我想为some_project安装依赖项。我知道我可以把cd放入某个项目,然后运行npm安装。
But I was wondering if it's possible without changing the directory ? Something like
但是我想知道不改变目录是否可行?类似的
npm install some_project/package.json
2 个解决方案
#1
234
You can use the npm install <folder>
variant with the --prefix
option. In your scenario the folder and prefix will be the same:
您可以使用npm install
npm --prefix ./some_project install ./some_project
#2
38
Update: Since the --prefix
option exists, I now vote for @coudy's answer to this question. Original answer below:
更新:由于——前缀选项存在,我现在投票给@coudy对这个问题的回答。最初的回答如下:
No, npm
will always install in the current directory or, with -g
, in the system wide node_modules. You can kind of accomplish this with a subshell though, which won't affect your current directory:
不,npm将始终安装在当前目录中,或者在system wide node_modules中使用-g。你可以用一个子shell来完成,它不会影响你当前的目录:
(cd some_project && npm install)
The parentheses makes it run in a subshell.
圆括号使它在子shell中运行。
#1
234
You can use the npm install <folder>
variant with the --prefix
option. In your scenario the folder and prefix will be the same:
您可以使用npm install
npm --prefix ./some_project install ./some_project
#2
38
Update: Since the --prefix
option exists, I now vote for @coudy's answer to this question. Original answer below:
更新:由于——前缀选项存在,我现在投票给@coudy对这个问题的回答。最初的回答如下:
No, npm
will always install in the current directory or, with -g
, in the system wide node_modules. You can kind of accomplish this with a subshell though, which won't affect your current directory:
不,npm将始终安装在当前目录中,或者在system wide node_modules中使用-g。你可以用一个子shell来完成,它不会影响你当前的目录:
(cd some_project && npm install)
The parentheses makes it run in a subshell.
圆括号使它在子shell中运行。