NodeJS Deployment via Render.com

NodeJS Deployment via Render.com

In this blog article, we will see how we can deploy an Express-based application on Render.com

With the recent news Heroku stopped their Free tier which allowed to host a lot of web services for free for hobbyists, especially around development or POC (Proof of Concept) times or side projects lot of developers are looking for alternatives that are as simple as using Heroku for quick deployment.

One such service is Render

Render is a unified cloud to build and run all your apps and websites with free TLS certificates, a global CDN, DDoS protection, private networks, and auto deploys from Git.

I had a lot of services ranging from Java, Golang, and Python to NodeJS.

For Python, I moved to deta.sh article on how to host FastAPI Python services on deta.sh can be found here.

For NodeJS, I decided to try Render for many other services it provides for my hobby projects if any. It's easy to set up, scale, and a lot of other features etc.

Setting UP Account

The first step is to create an account on Render, which is free of cost and requires no credit card. Better to sign up with something like GitHub or Gitlab for a future CI/CD perspective.

Once you authorize, confirm and verify the account we are ready to go.

Create Sample Express NodeJS application

We will quickly scaffold a simple Express NodeJS application. Make sure you have Node (+ NPM) installed as prerequisites.

npm init --y  // quickly initialize Node project.

Install express as below

npm install --save express

Create app.js below minimalist express code.

const express = require('express')
const app = express()
const port = process.env.PORT || 3001;

app.get('/', (req, res) => {
  res.send('Express hosting on Render.com')
})

app.listen(port, () => {
  console.log(`Listening on port ${port}`)
})

Code is pretty self-explanatory, we have written a simple root('/') endpoint which returns a String message "Express hosting on Render.com" exposed on port 3000

On accessing the root endpoint, we are able to get a response as below 2.JPG

Push code to GitHub account, by creating a new repository or existing is fine too.

Hosting on Render.com

Login to your render.com account, you will see the dashboard below which has a plethora of services. 1-dashboard.JPG

We will be using the "Web Services" service to host our express application.

Click on New Service, it will ask you to connect either to GitLab or GitHub account.

3.JPG

We will be connecting to GitHub account where we push our code in the previous step. We will select a single repository against which we pushed our Express NodeJS code as below. And Click Install

4.JPG

Once installed, it will show the account and which repository we selected as below. Now click on Connect against the repository of your choice.

5.JPG

Fill in all details like Unique name of service, Environment, Region of deployment, Branch, Build command, and Start command to run the app.

6.JPG

In the Build command, we gave a change directory as we are following the mono repository concept for my blogs.

Select Free plan to start and click Create Webservice.

This will start the build process, and log out things in the console as below

7.JPG

NOTE: Build failed, due to invalid start command. We need to update the directory to where our app.js file exists, before firing node app.js

This start command can be re-updated in the settings tab, as below 8.JPG

On change of command, the build will auto-trigger. You can view deployments in Events tab of the respective application as below

9.JPG

Voila! Our service is successfully deployed on render.com via Continuous deployment in place. It can be accessed via <app-name>.onrender.com, in our case it is nodejs-render-blog-demo.onrender.com

NOTE: You can obviously set up an API Gateway or Custom domain on top of it.

Informational

Render.com just like Heroku has a free tier which is more than enough to run hobby or side projects before needing to upgrade if required.

We can set up Webservices (Python, Golang, NodeJS, Ruby, Rust, Php, etc.) and PostgreSQL for free to start like Heroku had earlier.

Web Services allows 750 hours of running time per month, before getting renewed. But they get inactive after 15 mins of inactivity. So we can use some services UptimeRobot to keep them active, by pinging them. Free Usage hours can be tracked at Billing Page

I personally think render.com with a lot of services available and the ability to convert Hobby projects into Side Projects on the same platform is quite easy and affordable.

Resources

Thank you for reading, If you have reached it so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback and suggestions!

I would love to connect with you at Twitter | LinkedIn.

Did you find this article valuable?

Support Virendra Oswal by becoming a sponsor. Any amount is appreciated!