Deploying a React & Node.js App to a Windows Server

2 min read
Deploying a React & Node.js App to a Windows Server

A half-empty cup of lukewarm coffee in hand, heart-racing with excitement…there is a smug look on your face, you can feel it (most programmers know this feeling I assume). You take a sip whilst looking at your just completed Web Application. You have been at it for days, months or years maybe, and finally, it is done 🍾😄.

However, there is one last proverbial mountain you still need to climb to complete this journey, the application works only on your machine 😥. The lead shoes on this last bit of this journey is a requirement for deploying the application on a locally hosted Windows server provided by your client. The purpose of this article is to convert this task from a mountain into a molehill and hopefully, save you the reader time.

Step 1: Deploying the NodeJs Server App

  1. Install Node.js on the target Windows server
  2. Install pm2 from npm in your server application. PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, reload them without downtime and facilitate common system admin tasks.
npm install pm2 -g
  1. Start the your server application using pm2
pm2 start server.js

Your server app is now daemonized (running in the background), monitored and kept alive forever. The server status will be shown in the terminal as shown below.

Image

You can now type your server address and port in the browser URL bar to access the server. For test purposes, I send text to the browser from my server home route using the following code

app.get('/' (req, res) => {
   res.send('Hello World 😎');
});

Typing ip_address:port_number in the URL bar, e.g. localhost:4000 will give the following output in the browser

Hello World 😎

That’s all. The server setup is now complete. Next, we deploy our React App.