Deployment

With Now, you can deploy any kind of web app by using a single command. Now supports three types of deployments:

We have special categories for static and Node.js deployments because they are the most common among the deployments we handle. But you can also use Docker to deploy static and Node.js apps.

Here is how each of these deployments work:

With static deployment, you can deploy a static web app or a set of assets to Now. Visit the directory you want to deploy and run this command:

now

If that directory contains an index.html file, that file will be served. Otherwise, Now will show all the files in that directory.

Directory listing of a static deployment

For all static deployments, you will be charged only for the bandwidth. You do not pay for computing resources and storage.

To learn more about static deployments, read this guide.

If you have a package.json file in your app directory, Now considers that a valid Node.js deployment. Here is a simple Node.js deployment with the help of micro.

We have two files in our app directory. They are:

module.exports = () => ({
  date: new Date
})
{
  "name": "get-started-node",
  "version": "0.1.0",
  "dependencies": {
    "micro": "latest"
  },
  "scripts": {
    "start": "micro"
  }
}

To deploy this app, visit the app directory and run this command:

now

‚ÄčNow will install dependencies and run the start NPM script, as mentioned in the above package.json file.

You can also specify a separate build command, select the Node.js runtime and control dependency installation, and do more. To learn about those, read this guide.

If your app directory contains a Dockerfile, Now considers that a valid Docker deployment. It will build a docker image based on the Dockerfile and start container(s) based on that.

To deploy a simple Go HTTP server, create a directory and add these two files:

package main

import (
  "fmt"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello from Go")
  })
  http.ListenAndServe(":3000", nil)
}

A simple Go file that prints "Hello from Go".

FROM golang:1.9-alpine as base
WORKDIR /usr/src
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o main

FROM scratch
COPY --from=base /usr/src/main /go-http-microservice
CMD ["/go-http-microservice"]

A multi-stage build Dockerfile that enables the use of Go and runs our `main.go` file.

Note: Without enabling Now Cloud v2 with the following now.json configuration, the Dockerfile will require an EXPOSE instruction. In this case it would be EXPOSE 3000.

{
  "features": {
    "cloud": "v2"
  }
}

Enabling Now Cloud v2 from a `now.json` configuration file.

Create a whitelist for the files you want to use.

*
!main.go

A `.dockerignore` file that allows the `main.go` file to be in the Docker build context.

Now run this command inside that directory:

now

That's it. You'll get a URL like this: https://go-hello-isftssqinn.now.sh

To learn more about Docker deployments on Now, read this guide.