简体   繁体   中英

How can i start node typescript process (Express API) in background?

I have a express API i need to start this process in background to continue when i close the connection (Ubuntu Server - Terminal)

node --inspect -r ts-node/register server.ts

Thanks

In regards to NodeJS applications, check out PM2 to run, and automatically restart your application in the event of a crash or system reboot .

npm install -g pm2
pm2 start server.js
pm2 save
pm2 startup

Generally in production, you should be utilizing your transpiled JavaScript, instead of TypeScript directly, hence my use of server.js , but nothing stops you from integrating TypeScript with PM2 .


For a more broad answer, screen can be used to run processes in the background. This should be installed by default, if not run: sudo apt install screen

Using screen:

  • Run screen -S <session_name> to open a new session, press SPACE to push through the licensing gibberish.
  • Start the desired processes in your screen session.
  • Press CTRL A then CTRL D to detach from the session; this will continue to run even if you close your terminal.
  • Run screen -r <session_name> to return to your screen session, screen -list lists all active screen sessions.
  • Press CTRL D or run exit in a screen session to terminate it.

View the manpages for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM