Real-time deployments with Zeit’s Now

This post was originally published here.

Update: 2017–03–13: Added content about Databases and the now-API.

This time I want to share with you an amazing project made by Zeit, the creators of socket.io and mongoose.
Now will deploy your JavaScript (Node.js), Docker or static projects to the cloud at the speed of light. Almost all you have to do is execute one single command in the console and you will get a URL where you can see your deployed project.

I will only show how it works with a Node.js App. But the same principles apply for Docker and static projects.

You have two ways to use Now:

  • CLI tool (install with npm i -g now)
  • Desktop version, available for download here. It also includes the CLI tool.

After successfully logging into your account, you are ready to deploy “whatever” you want in seconds.

Logging-in with the CLI:

CLI output

Desktop version welcome page:

Image for post
Image for post
Image for post
Image for post

Deploy a simple Express App


Note: it is mandatory to have an npm start or now-start script defined in your package.json in order to deploy. For example:

(For npm build you can also have a specific now-build script. The same principle as above applies)

Now let’s deploy!
Here, again you can use the CLI or drag&drop your folder to the Desktop application.

That’s how the CLI tool looks like:

Now the Express App is publicly available under https://zeit-now-test-gedqsinqpr.now.sh.
And it took only about 2 seconds. Impressive!

Using custom deployment names

But maybe you do not want to have a new URL each time you deploy your project… if that’s the case, Now has you covered.
For that, you will need to create an alias:

The first parameter has to be a URL of an already existing Now deployment. You can check the list of deployments with now ls.
The second parameter is the custom name of the alias, so it generates the URL https://zeit-now-test.now.sh.

After each new deployment you can update the alias repeating the command above with the newest deployment URL.

With the premium version (which costs $14.99/mo) you can even point your deployment to a custom domain.
(Some domains as *.de are not working yet though).

View the source code of the project

Image for post
Image for post

If you have a premium version you can set your projects to private and the source code will not be shown.
For the free version all the project are by default public.

Use environmental variables

Let’s say I want to have a variable called SALUTATION and use it in the Express App we created before.

There are three possible ways to do that:

Passing them manually upon deployment

Resulting in:

Image for post
Image for post

Storing them in package.json, within an npm script

And then run the script:

The result is:

Image for post
Image for post

The other, and best way is to use secrets

To create a new secret just run:

Then just adapt your npm script to use the new secret (@salutation):

… and execute npm run deploy-to-now.


Image for post
Image for post

Using databases

Well, as far as I know there is no way to deploy a DB using Now, because you basically have
no access to the server where your app is being deployed. So the best option is either
deploying your DB service separately or just using a DBaaS (Database as a Service provider.

I am doing a lot of stuff with MongoDB, so some popular services that I can recommend for it
include MongoDB Atlas or mLab.
The last one is pretty easy to configure and offers a nice free tier that gives you 500mb,
which is actually more than enough for small projects.

I am pretty sure that there are good service providers also for other Databases.

Using the API

It is very well documented here and the guys at Zeit even wrote a JavaScript client that you can find on GitHub.

Image for post
Image for post


Try it out and feel free to leave your comments below!

Written by

Full-Stack Web Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store