deploying a node.js project on cloudfoundry (mac osx)
If you don’t have your cloudfoundry credentials create here: www.cloudfoundry.com
I’ve run into a bug using Mac’s ruby. If you already use rvm and ruby 1.9.2, you can skip the first step. Found the bug solution here.
Setting up Ruby
Install rvm:
Add the following lines to ~/.bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . “$HOME/.rvm/scripts/rvm”
Update your terminal env with source or open a new terminal
Now install ruby 1.9.2
$ rvm use 1.9.2
Configuring cloudfoundry
Install the vmc gem
Set the target
Login with your credentials… vmc will ask for your email and password.
Creating a simple express app
* You need Node.JS and NPM from now on
$ cd sample-project
$ express
Start your app to check its running:
Open http://localhost:3000 and see the Welcome to Express msg :)
Configuring your app to run on cloudfoundry
Install cloudfoundry module
Change your app.js to run locally and at the cloudfoundry
Require the cloudfoundry module
Go to the app.listen line at the end of the file and change to:
Create a file called package.json and put the used modules:
*jade is the view engine
”name”:”sample-app-bfuster”,
”version”: “0.0.1″,
”dependencies”: {
”express”:”",
”cloudfoundry”:”",
”jade”:”"
}
}
Bundle those modules into your project
Deploy your app
Console output:
Application Name: sample-app-bfuster
Application Deployed URL: ‘sample-app-bfuster.cloudfoundry.com’?
Detected a Node.js Application, is this correct? [Yn]: y
Memory Reservation [Default:64M] (64M, 128M, 256M, 512M or 1G)
Creating Application: OK
Would you like to bind any services to ‘sample-app-bfuster’? [yN]: n
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (33K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK
Running app: http://sample-app-bfuster.cloudfoundry.com
source: https://github.com/bfuster/cf-sample-app
