Using pm2 status Command for Node.js Apps

Using pm2 status Command for Node.js Apps

Using pm2 status Command for Node.js Apps


Step 1: Install pm2

If you haven't already installed pm2, you can do so via npm (Node Package Manager).

  1. Open your terminal or command prompt.
  2. Run the following command to install pm2 globally:
    npm install pm2 -g

Step 2: Start Your Node.js App with pm2

Assuming your Node.js app is ready, start it using pm2 to manage it.

  1. Navigate to your Node.js app's directory in the terminal.
  2. Start your app using pm2:
    pm2 start app.js
    pm2 start server.js --name "backend"
    Replace app.js with your main application file.
  3. pm2 will start your app in the background and manage it, ensuring it restarts if it crashes and other management tasks.

Step 3: Check the Status of Your Apps

Use the pm2 status command to see the current status of your Node.js apps managed by pm2.

  1. In your terminal, simply type:
    pm2 status
  2. You'll see a table displaying information about each app managed by pm2, including its name, status (online or stopped), CPU and memory usage, and uptime.

Step 4: Additional pm2 Commands

pm2 offers other useful commands to manage your Node.js apps:

  • pm2 list: List all running apps and their status.
  • pm2 stop app_name_or_id: Stop a specific app.
  • pm2 restart app_name_or_id: Restart a specific app.
  • pm2 delete app_name_or_id: Delete an app from pm2's management.
  • pm2 logs: Display logs for all apps managed by pm2.

Summary

Using pm2 status command allows you to easily monitor the status of your Node.js apps, ensuring they run smoothly and efficiently. pm2 simplifies app management, providing features like automatic restarts and performance monitoring.

Post a Comment

0 Comments