these days I’m developing a NodeJS app. Thanks to OpenShift you can upload your NodeJS code and start playing with it on Internet for free. You also have Heroku, but OpenShift gives you three cartridges (containers like?) for free while Heroku gives you one dyno.
Unfortunately the OpenShift NodeJS cartridge is a little outdated (version 0.10) and I wanted to use the 4 LTS version.
Out there, you have several resources to run your custom Node version, they are all awesome and helpful.
- https://github.com/ryanj/nodejs-custom-version-openshift (A fork from Ramr)
The READMEs on those github repos will guide you on how to install a simple web app using an updated Node version.
Anyway, I wanted to deploy my own code directly in OpenShift so these are the steps I follow just in case it may help you somehow. I’m using the Ramr repo, so a big thank you to him for the impressive work.
I assume that you already have an OpenShift account and that you’ve added your SSH public key.
Ok, I begin creating a nodejs 0.10 app using OpenShift’s web console. Once the app is created, I copy the repo URL which will be a string like ssh://XXXXXXXXXXXXXXX@app-name-domain-name.rhcloud.com/~/git/appname.git/
Now I clone Ramr repo inside the /tmp directory:
git clone git://github.com/ramr/nodejs-custom-version-openshift.git
Then, from the directory where my code lives (which uses git, of course), I copy the .openshift folder:
cp -rf /tmp/nodejs-custom-version-openshift/.openshift/ .
I add the following line to the package.json file, change it with the name of the file launching your Node service like server, app or in my case ./bin/www:
Now I edit the .openshift/markers/NODEJS_VERSION file and add the exact version of NodeJS which I want to use e.g 4.4.2 (the icflorescu for instance creates a cartridge which updates to the latest Node version available, which is great! so have a look as well).
I add and commit the changes on my repo:
git add .
git commit -a -m “Openshift with custom node integration”
I create the remote repo for OpenShift using the URL I copied earlier, use your own git repo URL from OpenShift!
git remote add openshift ssh://blahblahblah.git/
Ok, now I’ll force the code upload to the OpenShift repo. I’ll do this the first time only, later pushes can be used without forcing it:
git push openshift master -f
If everything is good when uploading the code to OpenShift you’ll see some lines like the following, which means that your desired Node.js version is being installed.
remote: Activating deployment
remote: – Checking to see if Node.js version 4.4.2 is installed …
Hopefully you’ll finally see:
remote: Deployment completed with status: success
This ends my first ever Node.js blog post, I hope you find it useful.