npm script command to run a script command from another package.json

I have two separate projects that use npm - so I have both : some_base_folder/projectA/package.json and some_base_folder/projectB/package.json

Each of those files has a scripts section in it.

If I go to some_base_folder/projectA/ and run npm run-script test it executes the test command from the scripts section of some_base_folder/projectA/package.json as it should.

What can I put as the value of "scripts": {test_projectA:'????' in some_base_folder/projectB/package.json so that when I am in some_base_folder/projectB/ and I run npm run-script test_projectA it will be execute the test script of Project A?

I tried ../projectA/npm run-script test but it says:

'..' is not recognized as an internal or external command,
operable program or batch file.

I am running under windows 7 but would prefer a solution that would also work properly on linux.

well it turns out to be quite simple:

"scripts": {
  test_projectA:"cd ../projectA && npm run-script test"

Example of calling one script from another � GitHub, @ashutosh-sharma You can use && to run two or more commands in sequence. "scripts": { "start": "node src/server/index.js", "build": "npm run build-dev && npm� Trying to bind a script called license-checker to npm commands following these instructions I came up with this snippet in my package.json { "scripts": { "postinstall

You should use --prefix.

npm run [command] --prefix path/to/your/other/folder

And for yarn:

yarn --cwd path/to/your/other/folder [command]

npm-run-script, This runs an arbitrary command from a package's "scripts" object. If no "command " is provided, it will list the available scripts. run[-script] is used by the test, If you want your script to use different behavior based on what subdirectory you're in,� Run a lifecycle script for a package (descendant of npm-lifecycle) - npm/run-script. Run a lifecycle script for a package (descendant of npm-lifecycle) - npm/run-script.

I ended up using:

"scripts": {
   "job": "cd ./sub && \"$npm_execpath\" run subjob",

because this also works with yarn.

Helpers and tips for npm run scripts, You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/. NPM scripts are incredibly useful, they make those hard-to-remember commands accessible just by naming the script: npm run your_script_name You can create them in your package.json like so:

4 Solutions To Run Multiple Node.js or NPM Commands , Inside your NPM script, in the "start" command, or whatever you want to use to run your So in a package.json file, your "scripts” command might look It's a little bit of a different tack to run multiple NPM scripts at once from� From your command line run the following command: npm start Additional use case. My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.

How to Use npm as a Build Tool, As part of npm's core, it has the npm run-script command ( npm run for short). This command dives into your package.json and pulls out the scripts Object. The first Another cool feature about npm is that any script that can be� prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided. preshrinkwrap, shrinkwrap, postshrinkwrap: Run by the npm shrinkwrap command. Additionally, arbitrary scripts can be executed by running npm run-script <stage>.

Argument parsing, environment variables and other hidden powers , For example if our package.json looks like this: It also means that people can have multiple projects with different versions of the same command installed. When you run a command or script through npm run… , your� A common scenario: as part of your npm start script, you need to have more than one command run (like webpack --config webpack.server.js and webpack --config webpack.client.js). Up until now you might have only run one command per script – often npm start just does something like node server.js .

  • seems like the log statements from my child process are not being displayed. Any idea on how to do that?
  • you can use --loglevel verbose
  • This wound up being a significant improvement over the top-voted answer for me. With the top-voted answer I was getting some errors about conflicting bcrypt library versions (I think because I was using the NPM libraries from where I ran the command to run the command in the other folder ... instead of its own). By using the environment variable as shown in this answer it fixed that. You should accept this answer IMHO.