Alex Merced I am a developer, educator, and founder of devNursery.com.

3 free Heroku alternatives to deploy a Node.js app

3 min read 1118

Heroku 3 Free Alternatives

For years, Heroku’s free tier has been the standard by which many developers released prototypes, hobby projects, and portfolio pieces to the public.

Unfortunately, Heroku announced plans to retire its free tier beginning on November 28th, 2022, leaving many developers scrambling to find alternatives to host their Bootcamp and portfolio projects. In this article, we’ll review three free alternatives to Heroku for deploying Node.js apps.

We’ll build a simple, framework-free Node.js app, and then deploy it to three different services that offer a free tier, Render, Railway, and Fly.io. Let’s get started!

Table of contents

Building our test app

We’ll build a plain vanilla Node.js server, but the same principles would apply if you’re using any of the popular Node.js frameworks, like Express, Koa, Fastify, NestJS, FoalTS, and more. You should already have Node.js installed on your machine.

Open your editor to an empty folder. Create a new Node.js project from your terminal using the npm init -y command.

Create an index.js file called touch index.js. In package.json, let’s set up our start script with the command below:

  "scripts": {
    "start": "node index.js"
  },

Inside of index.js, run the following code to configure a basic “Hello, World!” Node.js server:

// Import http library
const http = require("http")
// use env variable to define tcp/ip port with a default
const PORT = process.env.PORT || 8080
//create our server object
const server = http.createServer()
// We define a function that runs in response a request event
server.on("request", (request, response) => {
  // handle request based on method then URL
  response.statusCode = 200
  response.write("Hello World")
  response.end()
})
// get the server to start listening
server.listen(PORT, err => {
  // error checking
  err ? console.error(err) : console.log(`listening on port ${PORT}`)
})

Let’s test this locally by running node start and then heading over to localhost:8080.

If you see “Hello, World!”, then it’s working, and we can begin deploying it. From your terminal, create a git repository called git init. Add all of your files to staging with the git add . command, then make a commit with git commit -m"First Commit".

Next, you’ll head over to GitHub.com, create a new repository, and get the URL. Add your GitHub.com repo as a remote to your local repo and be sure to use your URL:

git remote add origin https://github.com/username/reponame

Then, push your code up to remote git push origin main. You can confirm whether your branch is main or master with the command git branch.

Now that we have our code up on GitHub, we can proceed with deploying it. You can check out my repo from this exercise for reference.

Deploying to Render

With its free tier, Render makes static deployments easy for React, Vue, and Angular apps or web service deployments for Node.js apps. Just follow these steps:

  • Log in to Render.com using your GitHub account
  • Click New > Web Service
  • Connect the GitHub repository you just created
  • On the next screen, give your project a name, accept all defaults and the free tier, and then deploy

From this screen, we wait for the deployment to complete, which can take a while. The URL for when it is done can be found in the upper left hand corner:

Render Deployment Complete

When it’s done, click on the URL they generated for you, and you should see our “Hello, World!” message. That was pretty easy, wasn’t it!

Render also offers other services that you may find useful as you build your application, like databases and cron jobs, which are scripts that run on a set schedule.

Deploying to Railway

Similar to Render, Railway is a service that allows you to deploy your application and provision several types of databases, like Postgres, mySQL, and MongoDB. The steps to deploy our Node.js application on Railway will be very similar to those for Render:

  • Login using your GitHub account
  • Create a new project and select deploy from GitHub
  • Select your repo, then select deploy now

It should complete pretty quickly, and you’ll see the following screen:

Railway Deploy GitHub Complete

By default, it will not have a publicly accessible domain name. To generate one, head over to the Settings tab and click Generate Domain. This will create a URL that you can use to share your project with others. That’s it!

Deploying using Fly.io

Fly.io focuses primarily on deploying Docker containers, and over the last few years, it has made the process much easier. First, sign up using your GitHub account. We’ll take a different approach when deploying with Fly.io:

  • Install Fly.io’s command line tool, FlyCtl
  • Log in with the command flyctl auth login. It will ask for payment info, but you won’t be charged as long as you remain within the free tier
  • From the terminal, deploy the app with flyctl launch
  • Answer the prompts and accept the defaults, then wait for the deployment to finish

It may take a while, but once it is deployed, you’ll see the application on your Fly.io dashboard as well as the URL it is located at.

If you need to update your app in the future, simply run the command flyctl deploy from the directory where your application is. It knows which deployment to update because when you ran flyctl launch, it created a fly.toml file with all the deployment settings for speeding up updates.

If it’s not working, check that the port that is exposed in fly.toml is the same one that is exposed in your index.js on line 4 as the default port.



Other deployment options

There are a growing number of services looking to fill this gap, but a different approach is to replace your backend needs with serverless functions, which also have a free tier on Vercel and Netflify. They are easy to use, but take some getting used to as we developers often think of our backend as one application instead of several serverless endpoints.

Conclusion

Yes, it is a little disruptive that we’ve lost Heroku’s free tier, but the resulting splintering across many different services like Render, Railway, and Fly.io will make the industry more resilient. With developers no longer beholden to one vendor, the competition for market share will accelerate the drive to innovation. I hope you enjoyed this article. Be sure to leave a comment if you have any questions, and let me know which service you prefer as an alternative to Heroku. Happy coding!

200’s only Monitor failed and slow network requests in production

Deploying a Node-based web app or website is the easy part. Making sure your Node instance continues to serve resources to your app is where things get tougher. If you’re interested in ensuring requests to the backend or third party services are successful, try LogRocket. https://logrocket.com/signup/

LogRocket is like a DVR for web and mobile apps, recording literally everything that happens while a user interacts with your app. Instead of guessing why problems happen, you can aggregate and report on problematic network requests to quickly understand the root cause.

LogRocket instruments your app to record baseline performance timings such as page load time, time to first byte, slow network requests, and also logs Redux, NgRx, and Vuex actions/state. .
Alex Merced I am a developer, educator, and founder of devNursery.com.

Leave a Reply