Search overlay panel for performing site-wide searches

Salesforce (Heroku) Recognized as a Leader. Learn More!

NodeJs

Deploy, Manage, and Scale Your Node.js Applications, Your Way

How Node.js applications run on Heroku

Deploy

Once you push your source, Heroku prepares your Node.js application for execution in a dyno – a smart container with a secure, curated Node.js stack.

Manage

Manage your portfolio of Node.js applications using a simple Dashboard. Metrics let you see your Node.js app’s CPU, memory, and throughput on a unified time axis.

Scale

The simplicity of the single-threaded EventLoop in V8 makes horizontal scalability a necessity. Heroku’s app hosting environment makes horizontal scalability easy.

Get started now with Node.js app hosting on Heroku

Deploying Node.js apps with Heroku

  • Initialize the local Git repository.
  • npm init initializes the Node.js project.
  • Create an index.js file to respond to requests with “Hello Heroku!”.
  • Add a start command to package.json.
  • Create and deploy the app to Heroku.
  • We’re live! curl https://calm-crag-27835-7c1291519c76.herokuapp.com

View Node.js Docs

Why Heroku for your Node.js applications?

Leverage GitHub integration and powerful add-ons

Heroku’s first-class GitHub integration and add-ons like MongoDB, Postgres and Redis allow you to extend, manage and deploy small, modular modern application architectures without operational overhead.

All Heroku Add-ons

Rollback to a binary copy of your app if you break production

Heroku’s build process streamlines Node.js deployments and produces a byte-for-byte binary copy of your application. This copy can be restored at any point using Heroku rollback.

How to roll back a release

Focus on your app, not configuring routing

Heroku configures routes and distributes HTTP traffic for your Node.js apps so you can focus on just writing code, not managing ELBs and Nginx. Heroku routes websocket traffic to the same instance of your app for session affinity.

HTTP routing docs

Node.js logo with the text "node" in black and a green hexagon representing the letter "o," and "js" in a smaller, green hexagon below.

Node.js on Heroku

“The versatility of JavaScript makes it a popular choice for many types of applications. And Heroku’s first class support of JavaScript makes it an exceptional choice to deploy and run these applications with ease.”

Black and white image of a person sitting casually, leaning back with one leg crossed over the other, in a relaxed pose.

Colin Casey

Node.js Language Owner

Heroku Node.js Support FAQ

Heroku automatically manages Node.js dependencies using either npm, Yarn, or pnpm. The platform defaults to npm, but will automatically use Yarn if a yarn.lock file is detected in your project or pnpm if a pnpm-lock.yaml file is detected in your project. This ensures the correct package manager is run to install the exact versions of your dependencies for a fast and reliable build.

The fastest way to get started is by following the official Getting Started on Heroku with Node.js guide in the Heroku Dev Center. This tutorial provides a sample application and walks you through the steps of cloning the repository, provisioning a Heroku app, and deploying your code with a simple git push heroku main command.

For apps using classic buildpacks or Cloud Native Buildpacks, Heroku’s Node.js version support follows the official Node.js support policy. This means Heroku supports all active Long-Term Support (LTS) versions, and versions are removed after they reach their End-of-Life (EOL).

You can specify the exact version your app requires in the engines section of your package.json file. It is strongly recommended to always declare a version to ensure a consistent and predictable build environment.

Heroku supports the entire Node.js ecosystem, from back-end APIs to full-stack applications. The most popular frameworks deployed on the platform include Express.js for its minimalist and flexible approach to building APIs. For full-stack applications, modern frameworks like Next.js (for React) and NestJS (for TypeScript) are also excellent and widely used choices.

Heroku’s Node.js buildpack automatically handles the build step for modern JavaScript applications. After installing your dependencies, the buildpack checks the scripts section of your package.json file for a build script. If this script is present, Heroku will execute it by running npm run build. This is the standard way to compile assets, transpile TypeScript, or bundle your front-end code for production before your application is deployed.

Yes. While npm is the default package manager, Heroku’s Node.js buildpack will automatically detect and use Yarn if it finds a yarn.lock file in your project, or pnpm if it finds a pnpm-lock.yaml file. When one of those files is present, the buildpack will run the appropriate install command (e.g., yarn install or pnpm install) instead of npm install, allowing you to use your preferred package manager without any special configuration.

The best practice for managing secrets, API keys, and other environment-specific settings is to use Heroku config vars. Config vars are environment variables that are securely stored with your application and are exposed to your code at runtime.

You can access these config vars in your Node.js application through the global process.env object. For example:

const apiKey = process.env.API_KEY;

This approach is not only a critical security practice for keeping secrets out of your code, but it also allows the same application codebase to be deployed across different environments (like staging and production) without any changes.

Yes. The WebSocket protocol is a core technology for modern, real-time web applications, providing a bidirectional channel for delivering data between clients and servers. Heroku’s platform has native support for WebSockets, allowing you to build these kinds of applications with Node.js.

With out-of-the-box support for popular libraries like Socket.IO and ws that ensure robust and stable connections, Heroku is a great choice for building real-time applications like chat apps, live dashboards, and collaborative tools.

Ready to Get Started?

Stay focused on building great data-driven applications and let Heroku tackle the rest.

Sign Up Now