How can I get npm start at a different directory?

Viewed 258133

I usually cd into the app directory and then run npm start.

It is my feeling that there ought to be some way to run npm start with a path parameter. But, the npm start documentation contains no such feature.

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

6 Answers

I came here from google so it might be relevant to others: for yarn you could use:

yarn --cwd /path/to/your/app run start 

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

& inside package.json add the following script

"scripts": {
   "preinstall":"cd $(pwd)"
}

This one-liner should work too:

(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 preserve the working directory:

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

I used this solution because a program configuration file I was editing back then didn't support specifying command line arguments.

Related