0
0
Node.jsframework~30 mins

PM2 for process management in Node.js - Mini Project: Build & Apply

Choose your learning style9 modes available
Managing a Node.js App with PM2
📖 Scenario: You have a simple Node.js app that you want to keep running smoothly on your computer or server. PM2 is a tool that helps you start, stop, and monitor your app easily.
🎯 Goal: Learn how to use PM2 to start a Node.js app, check its status, and stop it when needed.
📋 What You'll Learn
Create a basic Node.js app file named app.js that listens on port 3000
Install PM2 globally using npm
Start the app with PM2 using the correct command
Check the app status with PM2 and then stop the app
💡 Why This Matters
🌍 Real World
PM2 helps keep Node.js apps running without manual restarts, useful for websites, APIs, and background services.
💼 Career
Knowing PM2 is valuable for developers and system administrators to manage Node.js apps in production environments.
Progress0 / 4 steps
1
Create a simple Node.js app
Create a file named app.js with these exact lines to make a server that listens on port 3000 and responds with 'Hello from PM2!'. Use const for imports and app.listen(3000) to start the server.
Node.js
Need a hint?

Use Node.js http module to create a server and listen on port 3000.

2
Install PM2 globally
Write the exact command to install PM2 globally using npm: npm install -g pm2
Node.js
Need a hint?

Use npm with -g to install PM2 globally.

3
Start the app with PM2
Write the exact command to start app.js using PM2: pm2 start app.js
Node.js
Need a hint?

Use PM2's start command followed by the app file name.

4
Check status and stop the app
Write the exact commands to check the status of PM2 processes with pm2 status and then stop the app with pm2 stop app.js
Node.js
Need a hint?

Use pm2 status to see running apps and pm2 stop app.js to stop your app.