How to Deploy Node Applications: Heroku vs Now.sh

Share this article

Build a Node CLI

As Node.js continues to gain in popularity, new tutorials pop up teaching you to write server-side JavaScript apps and APIs. Once you’ve built your shiny new Node app, though, what then?

In this article, I’m going to take a look at a couple of options for deploying your Node applications. We’ll take a look at Now.sh and Heroku.

I’ll explain how to deploy your code to each platform and we’ll end the article with a short summary of the pros and cons. I’ll pay attention to options for monitoring, ease of use, offered functionality and what the free hosting plan includes.

Deployment with Heroku

To be able to deploy apps to Heroku, you will have to sign up at Heroku and install the Heroku CLI for your machine. I prefer working from my terminal!

Before we can start, we need to add some code to the Procfile. Heroku makes use of this file to determine how to execute the uploaded code.

The following code needs to be added to the file so Heroku knows what command should be executed to start the app:

web: node app.js

Once this is done, try to log in from the terminal by typing heroku login. Heroku will ask you to enter your login credentials.

Next, navigate to the root of your project and enter the command: heroku create. This creates an app on Heroku which is ready to receive the source code of your project. The name of the app on Heroku is randomly created.

To deploy our code to Heroku, simply use git push heroku master. We can visit the app with the command heroku open which will open the generated URL.

Pushing changes to Heroku

Changes can be pushed by following the normal Github flow:

git add .
git commit -m "Changes made to app"
git push heroku master
heroku open

Useful Heroku Commands

  • To make sure that at least one instance of the app is running: heroku ps:scale web=1 Because we are using the free platform, it is not possible to upscale your application. However, it is possible to downscale so no instances of the application are running: heroku ps:scale web=0

  • View the latest logs (stream) in chronological order generated by Heroku: heroku logs --tail It’s also possible to show the app logs only. App logs are the output of console.log() statements in your code and can be viewed with heroku logs --source app-name

  • Heroku provides the possibility to run your app locally at http://localhost:5000: heroku local web

  • List all Heroku apps: heroku apps

  • Remove a deployment: heroku apps:destroy --app app-name

  • Add owner (account) to access the app: heroku access:add me@email.com, same for removing heroku access:remove me@email.com

Heroku Environment Variables

If you are working with a .env file locally, you might want to use other environment variables for your Heroku deployment. It is possible to set these with heroku config:set PORT=3001. These values overwrite the variables set in you .env file.

To see all defined Heroku environment variables, just use heroku config. If you want to remove an environment variable for e.g. PORT, use heroku config:unset PORT.

Free Plan

  • Allows up to five Heroku apps
  • 512 MB RAM
  • No upscaling available, only one instance of app can be running at the same time
  • Sleeps after 30 minutes of inactivity
  • Randomly generated app names
  • Metrics about memory usage, response time and throughput available but not possible to add custom metrics

Heroku Metrics

Deployment with now.sh

Now.sh focuses on the developer experience (DX), which is kind of unique. They try to offer tools which are flexible and are incredibly easy to use. Now.sh is part of Zeit.co which have developed several tools.

To keep it simple, we will only install the Now.sh CLI through npm:

npm install now -g

Next, we need to sign up so we can use our credentials in the console. Both login and sign up happen at the login page. Every time you sign in, you will have to confirm your login attempt by verifying through email. After confirming, you will be redirected to your dashboard where you can view your logs and deployments.

To start using now, just type now in your console. The console will prompt your email. Fill in the correct email and verify this again by clicking on the verification email.

Now we are logged in, let’s take a look at the start script in our package.json. Now.sh uses this to start the application. This is what the scripts field looks like:

"scripts": {
  "start": "node app"
},

Let us start with deploying our code to now.sh. Make sure you are in the root of the code example. To start the deployment process, just hit now. I think you can see the developer experience there. Everything can be executed with just one keyword! If you make changes to the application and you want to redeploy it, just hit now in your console and you are good to go.

The URL of the app can be found in the console logs. More general logs about deployment or other now commands can be found at your dashboard.

Deployment with Now.sh

Customization and defining environment variables

One way to customize your Now.sh deployment is by using a now.json file. However, since we are already using a package.json file, we can add the required customization under a the now key. This configuration allows you to customize the app name and alias, set environment variables, specify the deployment type and define the engine.

"now": {
  "name": "my-first-app",
  "alias": "app1",
  "type": "npm",
  "engines": {
    "node": "4.7.2"
  },
  "env": {
    "NODE_ENV": "production",
    "PORT": "3001"
  }
}

It’s also possible to set the environment variables through the CLI: now -e NODE_ENV="production" -e PORT="3001".

If you want to provide a dotenv file, you can set the option now --dotenv, but maybe you want to use .env.production instead of .env? This can be solved with --dotenv=.env.production. Lastly, you can also add the production dotenv file to your package.json.

"now": {
  "name": "my-first-app",
  "alias": "app1",
  "type": "npm",
  "engines": {
    "node": "4.7.2"
  },
  "dotenv": ".env.production"
}

Useful Now.sh Commands

  • The possibility to add an alias to your deployment: now alias deploy-url aliasname

  • List all deployments with their unique code: now ls

  • Remove a deployment: now rm unique-code

  • Force a new build (in case of issues): now -f

  • Scale your web app (free plan max 3): now scale deployment-url 3. Sometimes, it is not easy to predict the amount of traffic. Now.sh enables you to set auto scaling with a min and max value: now scale deployment-url min max.

Monitoring Logs

Log output can be retrieved with: now logs [deployment-url | deployment-id]. More advanced logging is also possible:

  • now logs -a -q "GET" -n 10 deployment-url: Shows the 10 latest logs containing the word GET.

  • now logs --since=20171028: Shows all the logs from the 28th of October 2017 (ISO 8601 format)

It is also possible to access your logs by clicking on an app in your Now.sh dashboard.

OSS plan Now.sh

The OSS plan is free to use and offers the following:

  • Bandwidth: 1GB
  • Log storage up to 100MB
  • Infinite amount of deployments possible
  • Concurrent instances is limited to 3
  • No support for custom domains
  • Max file size: 1MB
  • No auto-scaling support

The Bottom Line

Both Heroku and Now.sh offer great functionality. Now.sh focuses more on the developer experience by offering an easy to use CLI. On the other side, Heroku pays more attention to visual logging and especially monitoring with metrics.

Personally, I prefer the simplicity Now.sh offers by just using one keyword now for (re)deployment. For Node apps, I like the addition of the now property to the package.json file to customize your Now.sh deployment. No need to add extra files like the Procfile Heroku requires.

It’s hard to choose between both platforms. It just depends on your preferences and needs. Make sure to take a look at all the plans on offer. Good luck!

Frequently Asked Questions on Deploying Node Applications: Heroku vs Now.sh

What are the key differences between Heroku and Now.sh?

Heroku and Now.sh are both popular platforms for deploying Node.js applications, but they have some key differences. Heroku is a fully managed platform that provides developers with the necessary tools to build, run, and scale applications. It supports several programming languages, including Node.js, Ruby, Java, PHP, Python, Go, Scala, and Clojure. On the other hand, Now.sh (now known as Vercel) is a cloud platform for static sites and Serverless Functions. It is designed to work with many front-end frameworks like Next.js, Gatsby, and Nuxt.js. It also supports several back-end languages, including Node.js, Go, and Python.

How does the pricing of Heroku and Now.sh compare?

Heroku offers a free tier for developers, but it comes with limitations. For more resources, you need to upgrade to a paid plan. The cost depends on the resources you need. Now.sh also offers a free tier with some limitations. Their paid plans offer more features and resources, and the cost depends on your usage.

How easy is it to deploy applications on Heroku and Now.sh?

Both Heroku and Now.sh aim to make the deployment process as simple as possible. Heroku allows you to deploy directly from a Git repository, while Now.sh offers a command-line interface for deployment. Both platforms also offer integration with GitHub, making it easy to deploy your applications directly from your GitHub repository.

What kind of support does Heroku and Now.sh offer?

Heroku offers support through a variety of channels, including a robust online documentation, a community forum, and a ticketing system for paid customers. Now.sh, on the other hand, provides support through their online documentation and community forums. They also offer priority support for customers on paid plans.

Can I use custom domains with Heroku and Now.sh?

Yes, both Heroku and Now.sh support custom domains. On Heroku, you can add a custom domain through the settings of your application dashboard. On Now.sh, you can add a custom domain through the dashboard or the command-line interface.

How does Heroku and Now.sh handle scaling?

Heroku allows you to scale your application by adjusting the number of dynos, or server units. You can do this manually or enable autoscaling. Now.sh, on the other hand, automatically scales your applications based on the incoming traffic.

What kind of applications are best suited for Heroku and Now.sh?

Heroku is a good choice for a wide range of applications, from small hobby projects to large enterprise applications. It supports a variety of languages and frameworks, making it a versatile choice. Now.sh is best suited for front-end projects and serverless functions. It’s a great choice if you’re working with a front-end framework like Next.js, Gatsby, or Nuxt.js.

How secure are Heroku and Now.sh?

Both Heroku and Now.sh take security seriously. Heroku provides a range of security features, including automated system patches and updates, isolation between applications, and encryption of data at rest and in transit. Now.sh also provides strong security features, including automatic SSL, isolation between deployments, and protection against DDoS attacks.

Can I use databases with Heroku and Now.sh?

Yes, both Heroku and Now.sh support databases. Heroku offers a range of data services, including Heroku Postgres, Heroku Redis, and Apache Kafka on Heroku. Now.sh supports any database that can run inside a Docker container.

What kind of analytics and monitoring tools do Heroku and Now.sh offer?

Heroku provides a range of monitoring tools, including application metrics, log access, and alerting. You can also integrate with third-party monitoring services. Now.sh provides real-time deployment logs and allows you to integrate with third-party services for more advanced monitoring and analytics.

Michiel MuldersMichiel Mulders
View Author

Fullstack Blockchain Developer at TheLedger.be with a passion for the crypto atmosphere.

HerokuhostingnilsonjNode-JS-Toolsnode.jsnow.sh
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week