How to host NodeJs on Windows

1 min read

PM2 is a high performance, easy to use process manager for nodeJs. It’s free, cross-platform, open source and has a built-in load balancer. You can learn more about PM2 here.

Installation

Let’s install it globally. Open terminal of your choice and run the below command in any directory.

npm install pm2 -g

Done? Great!

Hosting Your NodeJs App

Hosting your app with PM2 is as simple as ABC. Open any terminal, navigate to your project’s root directory and run the below command.

pm2 start <YourStartUpFileName>.js
PM2 start-command result

That’s it. Your app is now hosted and is accessible on the port specified.

Other Useful PM2 Commands

1. PM2 list

PM2 list-command result

The above command will list all the processes registered at PM2.

2. PM2 stop

PM2 stop-command result

The above command will stop the specified process. You can specify the process by either process id or process name.

pm2 stop app.js // (By Process Name - Works in the project directory)
pm2 stop 0 // (0 is process id - Works everywhere)

3. PM2 delete

Deletes the specified process.

4. PM2 restart

Restarts the specified process.

5. PM2 monit

Monitors resource usage of applications.

Running PM2 on Windows Startup

  1. npm install pm2-windows-startup -g
  2. pm2-startup install

For saving the current list of processes, run below command

pm2 save

Now, on every window restart, your saved list of processes will be running again. Make sure you run save command after adding new processes.

Impressed? PM2 Plus has a lot more to offer. A Web based fancy dashboard for real time monitoring, metrics, notifications, issue tracking, wait wait, Why I am explaining all this, Go see yourself!

Thanks for reading. If you enjoyed this article, feel free to hit that clap button 👏 to help others find it.

Leave a Reply

Your email address will not be published. Required fields are marked *