Run npm script from another directory
npm
To run an npm script from another directory, use —prefix:
npm --prefix <path> run <command>
yarn
To run a yarn script from another directory, use —cwd:
yarn --cwd <path> <command>
Example
If you have a package.json in the example directory:
{
"scripts": {
"start": "echo hello world"
}
}
In the following directory:
.
├─ example
│ ├─ package.json
├─ package.json
1 directory, 1 file
Then to run script start from your working directory:
npm --prefix ./example run start
yarn --cwd ./example start
{
"scripts": {
"start": "npm --prefix ./example run start"
}
}