Skip to content
ciberch edited this page May 15, 2012 · 16 revisions

How to run node-express-boilerplate on Cloud Foundry

Prerequisites

  • A Cloud Foundry account. Signup Page
  • vmc command line tool to deploy to Cloud Foundry Instructions
  • NodeJS running locally on your machine. See Instructions.
    • Install version 0.6.8 or later. NPM is the package manager which will be included
  • Redis running locally
  • Apps on Facebook, Twitter and GitHub for prod and local environments

Get keys for all social networks and services

Build your Facebook App at

Build your Twitter App at

Build Github App at

Remember to get keys for localhost and for cloudfoundry (decide what app name you will want)

Steps

Clone @mape's repo or fork it and clone your fork and install the dependencies

git clone https://github.com/mape/node-express-boilerplate
cd node-express-boilerplate

Edit package.json to include module cloudfoundry

{
  "name" : "node-express-boilerplate",
  "description" : "A boilerplate used to quickly get projects going.",
  "version" : "0.0.2",
  "author" : "Mathias Pettersson <[email protected]>",
  "engines" : ["node"],
  "repository" : { "type":"git", "url":"http://github.com/mape/node-express-boilerplate" },
  "dependencies" : {
    "cloudfoundry": ">=0.1.0",
    "connect" : ">=1.6.0",
    "connect-assetmanager" : ">=0.0.21",
    "connect-assetmanager-handlers" : ">=0.0.17",
    "ejs" : ">=0.4.3",
    "express" : ">=2.4.3",
    "socket.io" : ">=0.7.8",
    "connect-redis" : ">=1.0.7",
    "connect-notifo" : ">=0.0.1",
    "airbrake" : ">=0.2.0",
    "everyauth" : ">=0.2.18"
  }
}

Install the dependencies locally.

npm install

cp siteConfig.sample.js siteConfig.js
export twitter_consumer_key=2SXwj3HcMHsdsdsL4uuUBdjShw
export twitter_consumer_secret=UFamzEOAEhLUwewewDwwEoCI72hN0fl8
export facebook_app_id=5925695687264066
export facebook_app_secret=cce6f5edefa89f4686e5e036e3ea
export airbrake_api_key=63340934f6b376a001eacfc660d06205
export github_client_id='92df9d93813ab234e1'
export github_client_secret='fa64d10d3a02eee08d00cda3c2965caea2a4ce22'
  • Run locally
node server.js

Install on CloudFoundry

  • Install vmc if you have not already done so
sudo gem install vmc --pre
  • Deploy the app to Cloud Foundry
  • Specify you want Redis "redis-asms" bound to your app
$ vmc push --runtime=node06 --nostart

  Would you like to deploy from the current directory? [Yn]: 
  Application Name: node-express-start
  Detected a Node.js Application, is this correct? [Yn]: 
  Application Deployed URL [node-express-start.cloudfoundry.com]: 
  Memory reservation (128M, 256M, 512M, 1G, 2G) [64M]: 128M
  How many instances? [1]: 
  Bind existing services to 'node-express-start'? [yN]: 
  Create services to bind to 'node-express-start'? [yN]: Y
    1: mongodb
    2: mysql
    3: postgresql
    4: rabbitmq
    5: redis
  What kind of service?: 5
  Specify the name of the service [redis-9bea7]: redis-asms
  Create another? [yN]: N
  Would you like to save this configuration? [yN]: Y
  Manifest written to manifest.yml.
  Creating Application: OK
  Creating Service [redis-asms]: OK
  Binding Service [redis-asms]: OK
  Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (305K): OK   
Push Status: OK
  • Run this command with your keys.
export APP_NAME=<your_name>
vmc env-add $APP_NAME airbrake_api_key=your_key
vmc env-add $APP_NAME github_client_id=github_id
vmc env-add $APP_NAME github_client_secret=github_secret
vmc env-add $APP_NAME facebook_app_id=fb_id
vmc env-add $APP_NAME facebook_app_secret=fb_secret
vmc env-add $APP_NAME NODE_ENV=production
vmc env-add $APP_NAME twitter_consumer_key=twitter_key
vmc env-add $APP_NAME twitter_consumer_secret=twitter_secret

To finish, run:

  vmc start