A deployment represents a copy of your application hosted in our cloud platform, accessible to you and your users via HTTP/2.

The deployment process gets triggered by either an API call, the now command, or git push if using our GitHub integration.

The deployment process involves two phases we handle on your behalf:

  • Source code synchronization: we take your application sources and upload them
  • Build steps execution: if you define build steps, we execute them and serve their outputs

The resulting deployment is:

Your First Deployment

To make your first deployment, we are going to use the Now CLI. If you have not installed it yet, please refer to the installation instructions (otherwise, run npm i -g now if Node.js is installed).

We start by creating a directory in which to place our deployment sources. Open up a terminal and write the following:

mkdir -p my-app && cd my-app

We are now inside the my-app directory. Use your favorite text editor to create an index.html file with the following contents:

<h1>Hello World</h1>
<marquee>This is my first Now Deployment</marquee>

All we have to do now is run now from within the my-app directory:

now

The output looks like the following and includes a deployment URL:

The output of deploying a simple application with Now CLI

Check the deployment for a live example: https://my-app-prtypks27.now.sh/

This URL is unique to the source code inside that directory. If you run now again, the same deployment is returned. This is why we call our deployments immutable.

Introducing a Build Step

When we created our deployment above, Now performed one phase: source code synchronization.

In most production applications, however, we typically want to transform sources into other outputs. Now supports two types of outputs:

  • Other static files. For example, we can take index.html and minify it or optimize a PNG
  • Lambdas (Serverless). These are entry points that are invoked when requested, execute code and respond dynamically.

Let's add a function that will be executed whenever the user goes to /date.js that outputs the date.

Create a file date.js with the following contents:

module.exports = (req, res) => {
  res.end(`The date is ${Date.now()}`)
}

And register a Build for it by adding the following to now.json:

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

When we run now, the output will look as follows:

The output of deploying a simple application including a build step with Now CLI

If we go to https://my-app-83iw09a84.now.sh/date.js we will get dynamic output.

Interestingly, if we go to https://my-app-83iw09a84.now.sh (the root path), you will find that our index.html file is not showing, and instead we get a directory listing:

The directory listing of our deployment, showing date.js.

It is important to understand that Now keeps track of sources and outputs. If you add the special pathname /_src at the end of the deployment, you will be able to inspect them.

Notice that in the source view, in the output tab, a date.js lambda was built (identified with the icon λ), but index.html is no longer present. This is a precaution Now takes when using Builds to prevent source files from being accidentally exposed to the outside world.

We can then use the @now/static build module to include our index.html file explicitly:

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

When we run now again, we will see all our outputs.

The output of deploying a simple application including multiple build steps with Now CLI

The end result is on display at https://my-app-4t1xyg9f7.now.sh, including the date.js Lambda: https://my-app-4t1xyg9f7.now.sh/date.js

Read More

Extend your deployments with all that Now offers: