Run npm script from another directory
19 Jul, 2022
👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page
npm Jump to heading
To run an npm script from another directory, use --prefix:
npm --prefix <path> run <command>
yarn Jump to heading
To run a yarn script from another directory, use --cwd:
yarn --cwd <path> <command>
Example Jump to heading
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"
}
}
← Back home