Heroku is a platform as a service (PaaS) that lets developers build, run, and operate applications entirely in the cloud. It supports many languages—Ruby, Java, Scala, Python, PHP, and more. Today we’ll look at deploying a Node application on Heroku: what to change in the code, how to configure Heroku, and the pros and cons of the free tier as it existed when this was written.
Note: Heroku’s free tier was discontinued in late 2022. The deploy workflow below still applies on paid plans; the free-tier sleep behavior in the pros/cons section is historical.
Originally published on Medium in FAUN.dev().
Prerequisites
We’ll cover the Heroku steps here, but you should know the basics of Git and GitHub, and Git should already be set up in your project. If you need that first, read this and come back:
Previous article: Initializing Git and Pushing Code to a Remote Repository
Install the Heroku CLI
Download and install the Heroku CLI from the Heroku Dev Center.
Create a Heroku account
Go to Heroku’s signup page, create an account, confirm your email, and accept the terms on the dashboard. If you already have an account, skip ahead.
Once the CLI is installed and you’re signed up, the dashboard looks something like this:

Log in to the Heroku CLI
Open your terminal, run heroku login, and press Enter. You’ll be asked to press any key to open a login window in your default browser (or q to exit). Enter your credentials if you aren’t already logged in in the browser; if you are, just confirm the login.
Changes required in our code
Open the project in your editor—we need a few updates before deploy.
Specifying the engines property in package.json
Tell Heroku which Node version the project should run on. I was on 14, so I specified 14:
{
"name": "projectName",
"version": "1.0.0",
"description": "Too cool for writing descriptions",
"engines": {
"node": "^14"
}
}
Responding to a SIGTERM signal
Heroku emits SIGTERM from time to time to tell the app that the dyno (Heroku’s name for the container running your app) is about to restart. That happens about every 24 hours so the process can stay healthy. Roughly 30 seconds before restart, SIGTERM is sent—an alarm to finish in-flight requests and shut down gracefully.
In the file where you start the server, add this at the end:
const server = app.listen(port, () => {
// ...
})
process.on('SIGTERM', () => {
console.log('SIGTERM received')
server.close(() => {
console.log('Process terminated')
})
})
SIGTERM is just an event the process can listen for, then take an action such as closing the server. That’s the code change—we’re ready to deploy.
Common gotchas
- Don’t hardcode the port. Heroku provides it as an environment variable, and the server must listen on that port.
- Either omit the hostname or set it to
0.0.0.0.
const port = process.env.PORT || 3000 // Use this
// const port = 3000 // Not this
app.listen(port, '0.0.0.0', () => {
console.log(`Server is running on port ${port}`)
})
// or don't specify the hostname at all
app.listen(port, () => {
// ...
})
Deploying our application
Creating a new app
From the project folder, run:
heroku create

Heroku generates a random name—mine was pure-ocean-63386—and the app URL looks like https://<name-of-project>.herokuapp.com. We’ll rename it later; that also updates the domain.
Heroku also adds a Git remote named heroku (for me, https://git.heroku.com/pure-ocean-63386.git). To deploy, push to that remote:
git push heroku master
After you run that, Heroku logs a lot to the terminal—installing dependencies, build succeeded, launching—and when it’s done the terminal looks something like this:

Open the URL (https://pure-ocean-63386.herokuapp.com for me). If you didn’t rely on environment variables and everything above is correct, the app should be live. If you get an application error page that says to check the logs, run:
heroku logs --tail
If you did use environment variables, they’re probably undefined: we don’t push .env files, so those values must be set on the Heroku dyno.
Setting environment variables on Heroku
Set config vars from the terminal:
heroku config:set FIELD_NAME=VALUE
# e.g. heroku config:set DBPASSWORD=9786ACCBG21IJK
# heroku config:set NODE_ENV=production # Heroku often sets this by default
After code changes, stage and commit, push again to the heroku remote, then open the URL. If it’s still broken, check the logs and debug from there.
Renaming the application
The random name isn’t related to the project. Rename it to something clearer:
heroku apps:rename <newname>
# heroku apps:rename akshattrivedi001
That renames the app (for example to akshattrivedi001) and updates the domain to akshattrivedi001.herokuapp.com.
The name must be unique across Heroku.
Pros and cons of Heroku’s free tier
As noted above, this section reflects the free tier as it worked in 2021.
Pros
- Easy to deploy with Git.
- No need to manage server configuration yourself.
- Good for personal practice projects.
Cons
- With no traffic for 30 minutes, Heroku put the app to sleep. The next visitor could wait 10–15 seconds for it to wake.
- That cold start was the main free-tier downside—most people won’t wait ten seconds for a site to open.
That’s the deploy path. For a shortcut instead of copying the URL into a browser, open the app from the terminal with:
heroku open
Thanks for reading—see you next time.



