Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Installation

To create a new project with Node.js:

  • Log in to the Divio Cloud Control Panel. 
  • Select Add new Project, with the following options:
  • Creation: New
  • Python: No Python
  • Boilerplate: Node.js or (to have React.js preinstalled) React.js

Local Development

Setting up a project locally is very easy and fast, the only commands you need to run a project are:

  • divio project setup PROJECT_NAME 
  • divio project run PROJECT_NAME 

You can install the Divio CLI by downloading the Divio App.

Documentation

For further documentation on Node.js please consult their official documentation.

Database

Divio Cloud provides a Postgres database for each project. You can connect to this by installing the "pg" package via npm install pg --save . An example configuration would look like:

const pg = require('pg');
const config = {
    user: 'postgres',
    database: 'db',
    password: '',
    host: 'localhost',
    port: 5432
};
const pool = new pg.Pool(config);
...

You can also get the connection information from the DATABASE_URL  environment variable which outputs :

postgres://postgres@db:5432/db

For further documentation please consult the "Pooling example" found in node-postgres.

Did this answer your question?