Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package.json: what is the difference between & and &&?

Title pretty much says it all, but I'd also like to know if these commands work or behave differently depending upon the OS.

example1:

"scripts": {
    "build": "babel -d serverbuild ./server",
    "exe": "node ./serverbuild/index.js",
    "start": "npm run build && npm run exe"
}

example2:

"scripts": {
    "build": "babel -d serverbuild ./server",
    "exe": "node ./serverbuild/index.js",
    "start": "npm run build & npm run exe"
}

Given these examples portions of a package.json, what would be the difference between npm run start?

like image 828
simon Avatar asked Feb 23 '19 12:02

simon


1 Answers

When using &&, the first command will run, and if it does not error, the second command will run. It's like a logical AND.

Using &, however, will run a command in the background. So in your second package.json, npm run build will start running in the background and then npm run exe will run as well regardless of what happens to the first command.

like image 65
Sayegh Avatar answered Nov 15 '22 16:11

Sayegh