How to use Now to deploy your Node.js application for free

Written by
Written on
Tutorial Category Web Applications
Experience level Intermediate

Introduction

Now is a tool that allows you to take a Node.js or other Docker-ready application into the cloud from the command line. It allows you to iterate and deploy changes quickly either manually or through a continuous delivery mechanism.

It’s super cool and free to try, so let’s give it a go!

What you’ll need

The Now Desktop client automatically installs the Now CLI which we will use to push our application. If you don’t want to install an entire desktop application to achieve this, you can easily just install the Now CLI on its own.

Create a new project (Optional)

If you don’t have a Node.js app hanging around – have no fear! We’ll make one now.

If you do – please move on to the next section. You don’t need to install micro either.

First, go to whereever you usually store your projects. For me, it’s ~/Projects:

$ cd ~/Projects
$ mkdir now-test-app

Then, lets initialise the project:

$ npm init

npm will ask you a few questions about your project. Fill them out. We will then copy the following into your package.json:

{
  "name": "now-test-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "micro": "latest"
  },
  "scripts": {
    "start": "micro",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

In case you were wondering, micro is a handy package for creating microservices. It removes some of the boilerplate that is inherent with packages like Express. Definitely worth checking out if you’ve not seen it before.

Anyway! At the moment, not a whole lot will happen when we visit our application. Let’s fix that. Create index.js, then add:

module.exports = () => 'Hello from CloudTutorials!'

Once this is done, you’re ready to deploy the application using Now!

Deploy the application

Heads up:
If you use the free version of Now, any and all source code in the project’s directory will be publicly viewable. Of course this does not apply if you pay for one of Zeit’s hosting plans, which are very reasonable.

Assuming you’re still in the same directly, deployment is *literally* as simple as this:

$ now

If it’s your first time using now, they’ll ask you to supply an email address. Fill it in and click the link from your Inbox. The process will continue.

They will then ask if it’s ok to proceed as, by default, you will be on the OSS plan, which means that any and all source code from your project will be publicly available at the _/src path.

If all goes to plan, you will be given a URL to paste into your browser. Give it a go! You’ll hopefully see the words “Hello from CloudTutorials” in your browser.

Cool, huh? Enjoy!

%d bloggers like this: