Resources for Developers

Get Started with Node.js on Scalingo

Requirements

Before doing this tutorial you should have setup your environment:

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)
})

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). This file must be at the root of your project. 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

$ 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...
<-- https://my-app.scalingo.io -->

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!


mode_edit Suggest edits