Learn how to deploy your Node.js application using the Now platform created by Vercel (formerly known as Zeit).

One of the easiest ways to deploy a Node.js application is through the Now platform created by Vercel. Now makes the deployment process fast and simple, acting as a cloud service that provides you with a URL to access your deployed application.

With Now, you can easily deploy Node.js apps, static websites, and more. Although Now supports multiple languages, this tutorial will focus on Node.js.

Getting Started with Now

Now offers a free plan to get started, which includes free SSL, 100GB of hosting, 1000 serverless function invocations per day, 1000 builds per month, 100GB of monthly bandwidth, and the use of a global CDN. If you need more, you can check out their pricing page for additional options.

To get started with Now, it is recommended to install Now Desktop, an Electron application that also installs the Now CLI tool. You can download it from the official GitHub repository. Alternatively, you can install the command line version directly from here if you prefer.

After installation, sign in with your email and Now will proceed with the authentication by sending you a verification email. Once signed in, you can follow the quick tutorial provided by Now.

Deploying an Application on Now

To deploy an application on Now, you can simply run the now command in a folder that contains your application. However, there is one requirement: the folder must include a now.json file with at least the following content:

{
 "version": 2
}

This ensures that your project runs on Now 2.

Once you run the now program, your app will be deployed to a random URL under the now.sh domain. For example, https://test-8h57iozp1.now.sh is a randomly generated URL. You can use this URL to access your deployed app.

It’s important to note that each time you update your app and run now again, a new random URL will be generated. This is because Now has a concept of immutability, allowing you to test multiple releases simultaneously, have multiple developers working on different parts of an app, and more.

To have a fixed URL for your app, you can create an alias using the command now alias. For example, running now alias test-m2vcwrsc8.now.sh test-flavio will create an alias test-flavio.now.sh that points to the deploy with the URL test-m2vcwrsc8.now.sh. This way, you can freely test new releases and update the alias once you are satisfied with the changes.

To remove a deployment, you can use the now rm <URL> command, where <URL> is the URL of the deployment you wish to remove.

Configuring a Lambda Function

Now allows you to execute a Node.js application on demand when visiting a particular URL. To do this, you can create a JavaScript file, such as test.js, with the following content:

module.exports = (req, res) => {
    res.end("Hi!");
}

In order to make it executable, you need to add a build step to your now.json file:

{
 "version": 2,
 "builds": [{ "src": "test.js", "use": "@now/node" }]
}

By heading to https://test-a0onzajf4.now.sh/test.js, you will see the result of running the JavaScript file.

However, you might notice that the index.html file no longer loads. This is because the default build step has been overwritten. To fix this, you can add another build step to your now.json file, specifically for the index.html file:

{
 "version": 2,
 "builds": [
     { "src": "test.js", "use": "@now/node" },
     { "src": "index.html", "use": "@now/static" }
 ]
}

Where to Go from Here

This tutorial is just the beginning of what you can do with Now. To further explore and expand your knowledge, you can check out these additional resources: