Skip to main content

Prerequisites

Before going forward, make sure you have the following prerequisites:
  • A server with root access
  • A domain name or IP address
  • A web server that can be used to serve static files
  • Nginx installed and configured on the machine
  • SSL configured for the domain name or IP address

Create a Small Express App

We will create a small express app to test the deployment. Here are the steps:
1

Install nodejs and npm on ubuntu

2

Create a project dir and initialize a node app

3

Install basic dependencies

4

Update the package.json

5

Create an index.js file and add the following code

6

Install pm2 to run this dummy app in the background

7

Run the application with the following command

This will start the application on port 8080.

Do a reverse proxy with nginx

Nginx can also act as a reverse proxy, forwarding client requests to other servers. Here are the steps to configure Nginx as a reverse proxy:
1

Edit your server block configuration

2

Configure the server block to act as a reverse proxy

3

Test and reload Nginx

4

Verify the configuration

Now, when you request http://<server_ip>/api it will return the following response:

Summary

In this guide, we learned how to deploy a Node API with Nginx on Ubuntu server. We also learned how to configure Nginx as a reverse proxy.

Next: Setting Up PostgreSQL with Docker

Continue your journey by learning how to set up PostgreSQL using Docker containers.