Logo

How to Install PM2 on Fedora 40

Mar 27, 2024

To install PM2 on Fedora 40, follow the steps below:

Step 1 : Install PM2 using npm

npm install pm2@latest -g

Step 2 : Run PM2 startup to generate and configure the startup script

pm2 startup

Step 3 : Create a simple Node.js application. For example, let's create a file named app.js with the following content:

const http = require('http');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, PM2!');
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/');
});

Step 4 : Start the app with PM2 : Navigate to the directory where your Node.js application resides and run:

pm2 start app.js

Step 5 : You can manage your application using various PM2 commands. For example:

- Restart the application:

pm2 restart app

- Reload the application:

pm2 reload app

- Stop the application:

pm2 stop app

- Delete the application from PM2:

pm2 delete app

Congratulations! You have successfully installed PM2 on Fedora 40.

Recommended