Getting Started with Node.js


Before doing this tutorial you should have setup your environment:

All the operation achieved with the 'scalingo' CLI can also be done on our web dashboard.

Initialize your application

$ mkdir my-app
$ cd my-app
$ npm init

# You need to fill the different info field for your project

$ npm install express --save
$ echo "node_modules" > .gitignore

Write a base server file

The main file for this sample project is server.js:

// Node.js - Express sample application

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')

var server = app.listen(process.env.PORT || 3000, function () {
  var host = server.address().address
  var port = server.address().port
  console.log('App listening at http://%s:%s', host, port)
The `process.env.PORT` will read the environment variable PORT dynamically provided by our container manager.

Define how to start your application

The Procfile (with a capital ‘P’) is the file defining how your application is supposed to start (more info about Procfile), here is the content you have to write in the Procfile file for this project:

web: node server.js

Commit your application

$ git init
$ git add .
$ git commit -m "Base Node.js application"

Create your application on Scalingo and deploy

This operation has to be done in the directory of your project.

$ scalingo create my-app
Git repository detected: remote scalingo added
→ 'git push scalingo master' to deploy your app

$ git push scalingo master

Access your application

Waiting for your application to boot...
<-- -->

How to keep your application alive

For Node.js apps we recommend to use a tool such as forever.

Now develop your project and build something amazing!

schedule 09 Feb 2015