loading...

Deploying Node/Express app on a Windows Server

massivebrains profile image Massive brains ・2 min read

I had this small side project I worked on for a client over a weekend, it was a simple express API.
Everything worked well and good until it was time to deploy! This was my conversation with the client..

Me: Cool so the app is ready, can you send me your staging server details so i can deploy for you?
Client: Yea cool, i will send you an RDP credentials to our Windows VM
Me: Wait what?

Ok jokes apart, lets get straight into it!

Before we continue, you should have a basic knowledge of Setting up a simple Express App and using Nodemon or any other Node Process manager.

To speed things up, i have setup a simple express app with a single endpoint for this demo, please note that the target is not necessarily an introduction to Express but how to deploy an Express based app on Windows.

GitHub logo massivebrains / express-demo

An Express Demo App

express-demo

An Express Demo App




You can clone the repo to follow along.

Setup the express app on the server

If you are using the sample app that was cloned, run yarn and then yarn start . The app should now start with nodemon. Assuming you have not changed the default port, head over to your browser at http://localhost:3000 . you should see the sample json response as below

{
  status: true,
  data: "Api Works"
}

Setting up a proxy with IIS

Now the app is running locally but not available outside the server. What we want is for the public to be able to reach the app at http://yourdomain.com/app where http://yourdomain.com is our domain.

Step 1

Search and open Internet Information Services (IIS)

Step 2

Expand Sites -> Default Web Site

Right click on Default Web Site and select Add Application

Adding a URL rewrite

Make sure the newly created app is selected under the Default Web Site, click on URL Rewrite from the IIS dashboard on the right.

On the right, click on Add Rule(s) and then select Reverse Proxy

On the inbound rules dialogue box, enter localhost:3000 as illustrated below.

If you changed the port number where the express app is currently running, make sure you use localhost:{port_number}

Click on OK after this.

Now head over to a browser (outside your server) and try to access http://yourdomain.com/api (where http://yourdomain.com) is your actual domain name.

Posted on by:

massivebrains profile

Massive brains

@massivebrains

I'm a full stack developer. I enjoy working on Node, Vue and Laravel. Hit me up if you have interesting solutions you would like us to build together.

Discussion

markdown guide