Keep Your Node.js Application Running 24/7
To keep a Node.js application running 24/7 on your VPS, you can use the screen command. Follow these steps:
Option 1: Using screen
1. Create a Screen Session
A screen session allows the bot to keep running even when you close the terminal. To start a new screen session, run:
screen -S dxrknxs-dev
Now, you're inside the new screen session. (You can replace PlexTickets with a name of your choice)
2. Start the Bot
Navigate to the folder where your application is installed:
cd /path/to/dxrknxs-dev
(Replace
/path/to/dxrknxs-tickets
with the actual path, e.g.,/home/dxrknxs-dev
)Start the application by running:
npm start
3. Detach from the Screen
Once the bot is running, you can safely detach from the screen session without stopping the bot. To do this:
Press
CTRL + A
, then pressD (All at the same time)
You will return to the regular terminal, and the bot will continue running in the background.
4. Reconnect to the Screen
If you ever need to access the bot or restart it, follow these steps:
List all active screen sessions:
screen -ls
You’ll see a list of active screens, something like:
12345.dxDevelopment
Reconnect to the screen session by running:
screen -r <screen_id>
(Replace
<screen_id>
with the actual ID, e.g.,12345
)
5. Stop or Restart the Application
To stop the application, simply press
CTRL + C
inside the screen session.To restart, run the
npm start
command again.
Last updated