How to Deploy an Express.js REST API on Render: An Alternative to Heroku
At the end of 2022, Heroku discontinued its free tier option resulting in the removal of the previously available free subscription plan for web hosting and other cloud services in its ecosystem.
Free tiers are particularly handy and cost-effective if you intend to deploy and host applications for a short period. Luckily, there is an alternative cloud platform that, like Heroku, offers a free tier for its cloud services among other perks.

In this article, we’ll explore how to deploy an Express.js REST API on Render, a cloud-based hosting platform.
What Is Render?
Render is a cloud hosting platform that provides a seamless and hassle-free way to deploy and manage static websites, fully-fledged web applications, backend APIs, or databases on the cloud. The features include:
Comparison Between Render and Heroku
Like the other cloud platforms, Render has its perks and drawbacks. But how does it compare to popular cloud solutions like Heroku?
Set Up a New Project on Render
To get started, header over toRender’s websiteand sign up and log into your account.
Render makes it easy to deploy and manage backend APIs by offering built-in support for popular programming languages and web services that streamline the deployment process.

This guide will make use of its web services feature to deploy an Express.js REST API. To follow along, you will need to first set up a PostgreSQL database instance on Render.
On the overview page, click on theNew PostgreSQLbutton to set up a new instance.

Next, fill in the name of your database, and click onCreate database. Finally, copy theInternal Database URLprovided. You will use it to configure the connection between your Express REST API and the PostgreSQL database.
Essentially, the Internal Database URL is used to establish a connection between applications running on Render’s servers such as a deployed API or a fully-fledged web application.

Nonetheless, if you only want to utilize the PostgreSQL database from an application deployed on another platform, you’re able to use theExternal Database URLto configure the database connection.
Create an Express.js REST API
Go ahead andcreate an Express.js web server. Next, install the following packages:
You can find this project’s code in thisGitHub repository.

Configure the Database Connection
To set up the connection between the Express.js API and Render’s PostgreSQL instance, in the root directory of your project folder, create adb.jsfile and add the code below.
Next, open theindex.jsfile, and add the code below thatimplements a simple REST APIwith four routes.
Set Up the migrate.js File
Create a new folder,scripts, in the root directory of your project, add a new file,migrate.js,and finally, add the code below:
This code will create a newuserstable in the database with two columns: an auto-incrementing primary key field and a name field.
Finally, add these commands to yourpackage.jsonfile.
Lastly, for create the user’s table on the database, you need to run themigrate.jsfile as a script on your terminal using the command below.
However, before running the command, make sure to retrieve theExternal Database URLfrom Render’s PostgreSQL instance settings information, and paste it into thedb.jsfile as the connection string.
This will establish a connection with the database instance from your local machine, allowing you to create the table before deploying the API. Once the table is created, you can then head over to your Render’s PostgreSQL instance, retrieve theInternal Database URL, and update thedb.jsfile accordingly.
Deploy the REST API on Render
First,create a new repository on GitHuband push the project code. Next, log into your Render account, click on theNew+button, and select theWeb Serviceoption from the drop-down menu.
Finally, access your GitHub account, select your project’s repository, and connect to it on Render.
On the web service settings page, provide a name for the new service, specify the root directory of the project, the build and start command, and finally, click onCreate Web Service. Once the deployment process is complete, copy the provided URL to test the endpoints on Postman.
Test the API Endpoints on Postman
Postman is a popular tool for developing and testing APIs. To get familiar with Postman,learn how to use it to test an API.
To test the deployed API, make aPOSTrequest to the /usersendpoint to store data in the PostgreSQL database.
Finally, make a GET request to retrieve the stored data.
Is Render a Viable Alternative?
Render provides a straightforward setup process, and seamless integration with popular version control systems making it a good alternative cloud hosting platform.
Moreover, its competitive pricing model and built-in support for popular development tools make it a reliable and user-friendly option for both side projects and large commercial applications.
Heroku’s cloud offering isn’t free anymore, but there are still good alternatives if you’re looking to migrate.
You’ve been quoting these famous films wrong all along!
Taming data is easier than it looks.
Goodbye sending links via other apps.
Anyone with more than a passing interest in motorsports must see these films.
It saves me hours and keeps my sanity intact.