Run multiple windows commands from nodejs

npm run multiple commands sequentially
yarn run multiple scripts sequentially
npm concurrently
npm run-script
package.json multiple commands
npm run command in new window
npm run two commands parallel

When my windows server receives a post request, I need it to execute a command:

cd D:\project
git pull
mvn clean compile
cd target
java -jar app.jar -argument

I wrote the code, but it does not work:

const nodeCmd = require('node-cmd'), res) => {
  let command = `cd D:\project\my_project
                 git pull
                 mvn clean compile
                 cd target
                 java -jar app.jar ${req.body.arg}`;
  nodeCmd.get(command, (err, data, stderr) => {
    if(data) { 
     return res.json(data);
    return err;

Here is the error message:

{ Error: Command failed: cd D:projectmy_project && dir
The system cannot find the path specified.

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'cd D:Tempautobooker && dir' }

The backslashes in your command string are not escaped. You can use string.raw to instruct the JS engine to treat a template literal as a raw string.

let command = String.raw`cd D:\project\my_project
                         git pull
                         mvn clean compile
                         cd target
                         java -jar app.jar ${req.body.arg}`;

Open multiple node.js servers with batch file, I'm using Windows. Currently every time I restart my server I have to run a bunch of commands to get my servers up and running and I'd like to consolidate them  Run multiple commands in a node package file? Run multiple sub-tasks in parallel (Mac, Linux, Windows) How can I update NodeJS and NPM to the next versions? 449.

I don't know much about running this kind of task in Windows, but I have a suspicion you may need to break these up into multiple calls or && between them.

4 Solutions To Run Multiple Node.js or NPM Commands , js backend server and your React UI server simultaneously, but in order to do so you have to open up two terminal (or more) windows, cd into two  I would like to C:\>ACommandThatGetsData > save.txt But instead of parsing and saving the data in the console, I would like to do the above command with Node.JS How to execute a shell comm

according to node-cmd documentation, your code is perfect , but what I believe is your problem lies in your project path which means your first command is not executed and this because your backslash not escaped, according to your error message your path is projectmy_project which is incorrect, you need to update your path to be like this D:\\project\\my_project

execute multiple shell commands in series on node.js · GitHub, shell.exec('npm test --coverage', function(err){. console.log('executed execute a single shell command where "cmd" is a string. exports.exec  Get started using Node.js on Windows for beginners. 09/19/2019; 10 minutes to read; In this article. If you're brand new to using Node.js, this guide will help you to get started with some basics. Prerequisites. This guide assumes that you've already completed the steps to set up your Node.js development environment on native Windows, including:

Executing Shell Commands with Node.js, With Node, we can run shell commands and process their I/O using JavaScript, instead of the shell scripting language. This makes the application easier to  Node.js is the key for many Javascript applications. As Node.js is still a go-to solution, many versions of it are released and new versions will be released in the future. That is where testing an…

How to run more than one command as part of a npm script – Corey , Rather than needing to have multiple scripts run, in multiple terminal/shell tabs, and having to remember the order in which to run them, it can be much easier. We'  W hen you are a NodeJS developer and you develop/run multiple applications on the local machine, this is a problem that you might have definitely encountered. This problem has become worse since new features are pouring into NodeJS and you have to keep up with the the flow.

a system call, These options expose built-in debugging, multiple ways to execute scripts, and Sets or resets the signal for report generation (not supported on Windows). If you were to run node --version after each of the aforementioned commands, you’d see the most recent version of the respective major version. nvm isn’t limited to major versions either, you could also run nvm install 12.0.0 to explicitly install the 12 dot oh dot oh version of Node.js. Listing Installed Node.js Versions

  • Can you show us the error message ?
  • I have update my question with error stack trace
  • escaping did help, just getting empty response, no errors or anything, tried with simple command cd D:\\projects\\my_project && dir
  • ok, this one helped now, the problem was as you said with the fact that I am using `
  • Tried that as well, no luck
  • That’s a bit beyond my expertise then, sorry about that. Have you tried using child_process straight up?
  • I just saw your error stack, you’re not escaping your backslashes `\` in your directory string. Try that.
  • escaping and adding & or && did not work
  • Escaping did not help too, I tried with the simple command: cd D:\\projects\\my_project && dir, which returned empty result, although there are several files and folders.
  • the empty result doesn't mean your command failed, try to add another command after cd to print the current path, try to add echo %cd% after cd D:\\projects\\my_project , and let us see what it print