13

How to install dependencies for project without changing working directory to project root?

Curently you need to execute:

cd /my/project/root && npm install && cd -

I'm looking for an option like -C for Makefile so that I can:

npm install -C /my/project/root

Any ideas on how to accomplish this?

Aalex Gabi
  • 1,525
  • 1
  • 18
  • 32

1 Answers1

18

A colleague of mine has found a way to do this (note that this is not documented in npm help but online):

npm install --prefix /my/project/root

Or the short version (only documented online)

npm install -C /my/project/root
Aalex Gabi
  • 1,525
  • 1
  • 18
  • 32
  • It's documented [on this page](https://docs.npmjs.com/misc/config#prefix) – E. Sundin May 09 '18 at 16:07
  • 1
    @E.Sundin indeed. Should be documented in `npm help` though. From that page it also seems that there is a `-C` option that does the same thing: https://docs.npmjs.com/misc/config#shorthands-and-other-cli-niceties – Aalex Gabi May 10 '18 at 18:24