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
:
{
"scripts": {
"command": "echo hello world"
}
}
In the following directory:
.
└── path
└── package.json
1 directory, 1 file
Then to run script command
from your working directory:
npm --prefix ./path/ run command
yarn --cwd ./path/ command