Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm - install dependencies for a package in a different folder?

Tags:

node.js

npm

People also ask

How npm install specific dependencies?

For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.

How install npm dependencies locally?

Steps: run npm i -g local-install. run npx install-local --save <local-path> inside the target repository to install the local dependency.

How install multiple dependencies npm?

The npm install command is used to install npm packages to a node_modules/ folder. You can also install a specific version of each package by adding the @version keyword after the package names. npm will install the exact versions you defined in the example above.


You can use the npm install <folder> variant with the --prefix option. In your scenario the folder and prefix will be the same:

npm --prefix ./some_project install ./some_project

Update: Since the --prefix option exists, I now vote for @coudy's answer to this question. Original answer below:

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:

(cd some_project && npm install)

The parentheses makes it run in a subshell.


On windows 10 using powershell the only thing that worked for me without all the problems and edge-cases mentioned in this blog post was this

Start-Process -Wait -FilePath "npm" -ArgumentList "install" -WorkingDirectory $web_dir