Execute multiple npm custom commands on Linux at the same time, both of which start the Node site. And run in the background.

"start-client": "cross-env NODE_ENV=production node ./server/index.js",
"start-api": "cross-env NODE_ENV=production node ./server/api/index.js",
"start-pro": "concurrently \"npm run start-client\"  \"npm run start-api\""

the npm run start-pro above can be run directly on linux, but the service exists and shuts down after shutting down the current session.

when I execute the command npm run start-pro & , I also run normally. After I close the session, the site has a 503 error. Use lsof-iVist8080 and lsof-icode 8686 to check if the port exists. It is found that the port of 8080 does not exist, but the back-end port of 8686 still exists. And then gave up the operation.

when I execute the command nohup npm run start-pro & , the file nohup.output appears in the root directory of the project, with the error:


> p2@0.1.0 start-pro /website/pgyer
> concurrently "npm run start-client"  "npm run start-api"

events.js:160
      throw er; // Unhandled "error" event
      ^

Error: EBADF: bad file descriptor, read
    at Error (native)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! p2@0.1.0 start-pro: `concurrently "npm run start-client"  "npm run start-api"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the p2@0.1.0 start-pro script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-07-18T00_30_14_968Z-debug.log

think of a way again, using nohup npm run start-api & to prompt for success! Also executed successfully after executing nobup npm run start-client & !

I am quite obsessive-compulsive. Here I would like to ask, how can I execute npm run start-api and npm run start-client with one command? is there any way?
Mar.28,2021

//package.json

"script":{
    "start-client": "cross-env NODE_ENV=production node ./server/index.js",
    "start-api": "cross-env NODE_ENV=production node ./server/api/index.js",
    "start-all": "npm run start-client && npm run start-api"
}
npm run start-all

is not familiar with nodejs and cannot help from the application level of nodejs, but if there is no good way, you can try the following two solutions

  1. write a shell script startup.sh , and start the two services through the script

     -sharp!/usr/bin/env bash
    
     nohup npm run start-api &
     nohup npm run start-client &
    

    execute . / startup.sh to start two services with one command

  2. the recommended way is PM2 to manage the node process. PM2 is responsible for starting, stopping and monitoring the node process.

@ bear balls

I tried it and added

 "start-all": "npm run start-client && npm run start-api"

execute nohup npm run start-all & this command. Check nohup,out and find that you can only execute start-client commands

.
Menu