Watch clock cover
Developer Tools

Setup a Node.js + Express App in 60 Seconds

Did you know we also include ready-to-go Node.js support? In fact, it only takes few quick steps to get a Node.js and Express app set up. All in less than a minute! Read here to find out how.

Angelo Dini

Angelo Dini

Information Architect

Before you begin, be sure to install the Divio Desktop application. Let's begin!

Step 1: Create a New Project

Start by creating a new project in the usual way from the Divio Control Panel and be sure to select :

  • No Python

  • Blank Project

  • Node.js

Project creation node projectThis will prepare a Dockerised Node.js boilerplate project based upon the official Docker image node:6.10.

Step 2: Choose Setup

In the Divio Desktop application, select your project and choose "Setup". This will pull down and sync all the files locally and you can start a server with the initial template application immediately.

Project setupIf you navigate to your newly created project on your local machine, you will see the familiar index.js and package.json and other files related to Docker configuration.

Note that if you prefer to use a later version of Node.js and are not readily familiar with Docker then simply change the Dockerfile "FROM" line to indicate which Docker Node image should be used. In this example we will the latest Node 9.

FROM node:9

You may need to rebuild your Docker image to reflect the change in Node.js docker image version.

docker build --no-cache .

Step 3: Add Express

Now you can add Express and any other Node.js modules in the usual way:

npm install express --save

Open the index.js file and replace the contents with the classic Hello World for Express.

const express = require('express')

const app = express()

app.get('/', (req, res) => res.send('Hello Node on Divio!'))

app.listen(80, function () {
  console.log('Listening on port 80')
})

You can verify everything is working as expected by starting your app in the usual way.

npm start

Step 4: Start Docker Container

Now start the Docker container by selecting Start from the Divio Desktop app. You can point your browser to localhost:3000 and you should be greeted by "Hello Node on Divio!".

Note that your app is listening on port 80 "inside" the container but this is port-forwarded to 3000 which you can access "outside" the Docker container. When deployed on Divio it will be available on port 80 / 8080 (https) as expected.

Deploy a projectStep 5: Release App

Finally to release your Node app to the world, choose the Deploy option on the test server. The Divio Desktop app will upload your project files and Divio will prepare the environment. Once complete, select the eye-icon to preview your freshly prepared public test site.

Deploy project to liveNow you can add your routing and static files as usual and since its now Dockerised for you, your local development environment will be identical to your test or live version.

If you need any help in your initial setup with Divio, try the getting started tutorial.

Node.js is a trademark of Joyent, Inc. and is used with its permission. We are not endorsed by or affiliated with Joyent.