Node.js on OpenShift? You bet your Javascript

Developers have asked, and we listened.  Node.js has been a commonly requested feature for application deployments on OpenShift and our engineers have been tucked away banging out the code to make this happen.  Not only do we support node.js, its super secure with our usage of SELinux, c-groups, and pam_namespaces

Follow these steps to get Node.js applications deployed to the cloud in minutes:

Step 1: (Skip if you already have an OpenShift account)
Signing up for an OpenShift account is both free and easy.  In order to sign up, we only ask for an email address and password.  We don’t ask for your first name, your dogs name, how many cats you have or anything else.  Why makes things complicated by asking for data we don’t need.

Step 2: (Skip if you have clients tools already installed)
Now that you have an account on OpenShift, you can interact with our system via various methods.  The method I prefer is the command line tools.  In order to install and use the command line tools you will need to have both ruby and rubygem installed on your system.  Given the various ways of installing these dependencies on each operating system, I will not cover it in this post.  That being said, it is installed by default on most linux and mac operating systems.

Once you have ruby and rubygem installed, simply type the following, using sudo access if required:

$ sudo gem install rhc

Step 3: Create an application
In order to create an application on the OpenShift Paas, you can issue a single command that will both allocated a node for your use as well as install all the required dependencies for running node.js.  From a command prompt, issue the following command:

$ rhc app create –a yourApplicationName –t nodejs-0.6

This will also create a git repository and setup some git configuration files that will allow you to commit and push code changes to your node.js application server.

Verify that your application is up and running by pointing your browser to your freshly created application:

http://yourApplicationName-yourDomainName.rhcloud.com

Step 4: Embed databases if you need
Now that we have our node.js application and running, you may want to add database support.  At the time of this writing, we support MongoDB, MySQL, postgreSQL and sqlite.  In order to use one of these databases, we need to embed the corresponding database cartridge.  This can be done with the following command:

$ rhc cartridge add –a yourApplicationName –c mongodb-2.0

The above will create a mongoDB database and make is accessible to your node.js platform.  If you wanted to use MySQL or another database, you would simply supply the cartridge name for the respective database.  To get a list of all available cartridges, you can issue the following command:

$ rhc cartridge list

Step 5: Code (That was point of this, right?)
Your application code has been clones from your git repository and is located in the directory where you issued the create application command.  At this point, change to the directory created and have a look around.  We provide a README file that will explain the layout of the application and how to include npm dependencies for your application.

Once you have made some changes, for your application code to served by your OpenShift node, you need to commit and push your change.

$ git commit –a –m “Added some source code”
$ git push

And that’s all there is to it.  You have a running node.js application complete with database support available on the cloud.

If you have any questions about using OpenShift, please contact us in one of the following ways:

Want to get started even faster?  Check out our quickstart guides posted on github at: www.github.com/openshift

 

Tags:

Hi,

Your rhc cmd to list the cartridges should be:

rhc cartridge list

instead of

rhc cartridge list

At least that is what I need to do since the last release.

PS. this list does not include node.js for me:

> rhc cartridge list

List of supported embedded cartridges:

Obtaining list of cartridges (please excuse the delay)...
mongodb-2.0, cron-1.4, mysql-5.1, postgresql-8.4, 10gen-mms-agent-0.1, phpmyadmin-3.4, metrics-0.1, rockmongo-1.1, jenkins-client-1.4

Regards, erics

Eric, thanks for pointing out the typo. Will update the post with correct usage.

You should be seeing nodejs as available if you have updated to the latest client tools.

sudo gem update rhc

Does this node.js implementation support the use of npm to pull in other modules to our node apps? Also, are we able to set our own environment vars to be used by our node.js apps? I ask because I would like to run a version of github's hubot (http://hubot.github.com/) on OpenShift. I currently have it running on Heroku (I know, blasphemy) but I would really like to move it to OpenShift.

Thanks!

Yes, we support pulling in NPM modules for your application. The README file in your application directory will explain how to do this.

Thanks!

i don't understand the rationale behind using deplist.txt instead of package.json.. I'm assuming its because there are non-node+npm apps on open shift? why not use package.json as the blueprint rather than txt?

+1, why re-invent some obscure TXT format when standard package.json is supported! All other node.js PaaS platforms have it.

FYI, OpenShift works with package.json now.

@kborcher: yeah you can pull modules from the npm registry.

To do that, just add the module name (and optionally @version) to the deplist.txt file in your application -- see the default sample and that will install/update those modules.
_
As re: env vars -- here's a couple of different ways to do it :
1. You can of course set 'em in a starting js file [default is server.js] via process.env.NAME and then invoke your app.js script.
2. The other option you have is to ssh into your app instance and set environment variables you need in your app's conf/node.env configuration file.
Ala:
app="insert-your-app-name-here"
ssh $(rhc app show -a "$app" | grep 'Git URL' | cut -f 3 -d '/')
rchsh> vi $OPENSHIFT_APP_NAME/conf/node.env

You can then add env variables in that file (and among other things set v8 options, change the starting js script node runs -- default is server.js).

HTH.

Wow, awesome info and very detailed response. Thank you! Time to move my bot. :)

There is unfortunately still none, right?

Hi,

Is Websocket supported? I use socket.io in my app, it fell back to use xhr-polling.

Thanks

I normally wish to develop locally and push up to OpenShift once I believe the app is kinda-sorta working. The initial application created via the rhc app create command does not include the express dependency so you get an error message:
"node.js:201 throw e; // process.nextTick error, or 'error' event on first tick"

My current workaround was to install express via "npm install express" inside of the openshift template application.
Then "node server.js" works

Hello, I've been wondering how to go about running a bot for Turntable.fm through OpenShift. I can't seem to find any instructions on this. I've only found the steps for running the bot from my own computer. I know that this project requires nodejs.

@theryanlee: Haven't come across anyone who tried this earlier; try creating a nodejs application on OpenShift and try using Turntable API's from here: https://github.com/alaingilbert/Turntable-API