How to start npm in another directory

I usually cd into the application directory and run npm start .

I feel there must be some way to start npm start with a path parameter. But there is no such function in the npm start-up documentation .

I tried only to find npm start./myapp does not work. Is there a way to do this?

+163
Mar 23 '16 at 7:50
source share
6 answers

This single line layer should work:

 npm start --prefix path/to/your/app 
+274
Jan 20 '17 at 20:46 on
source share

Below is the command where the project is the folder containing the package.json file

 npm run --prefix project dev 

works. Useful in docker apps.

+43
Mar 09 '17 at 14:17
source share

npm start --prefix path/to/your/app

& inside package.json add the following script

 "scripts": { "preinstall":"cd $(pwd)" } 
+6
Sep 28 '17 at 19:52
source share

I came here from Google, so this may be relevant for others: for yarn you can use:

 yarn --cwd /path/to/your/app run start 
+4
Dec 14 '18 at 10:40
source share

In this npm log issue , one work around can be done via npm config

 name: 'foo' config: { path: "baz" }, scripts: { start: "node ./$npm_package_config_path" } 

Under the windows of the scripts could be { start: "node ./%npm_package_config_path%" }

Then run the command line below

 npm start --foo:path=myapp 
+1
Mar 23 '16 at 8:32
source share

This one-liner should also work:

 (cd /path/to/your/app && npm start) 

Note that the current directory will be changed to / path / to / your / app after executing this command. To save the working directory:

 (cd /path/to/your/app && npm start && cd -) 

I used this solution because the program configuration file that I edited then did not support specifying command line arguments.

-2
Jan 27 '19 at 17:34
source share



All Articles