Email about spark.js and now my Saturday is gone!

A lit­tle while back I saw an email about spark.js and thought it would be cool to check it out. This Sat­ur­day morn­ing I fig­ured I would down­load it and play around a lit­tle while it stopped rain­ing out­side. 6 hours lat­er…

First, I must say I am not a node.js expert, but I have some expe­ri­ence with Ver­sion Con­trol Sys­tems (VCS, Sub­ver­sion as an exam­ple), I do know JavaScript and I have tin­kered around with var­i­ous lan­guages, hard­ware etc. All that being said, it took a bit for me to get a work­ing envi­ron­ment to play around with spark.js the way I want­ed to!

Here were the steps I took and snags I found. This is all on Win­dows 7

  1. Install node.js
  2. Install spark.js

From here you can try out some stuff and get respons­es in the con­sole, you can actu­al­ly stop here, but I thought I would take it a few steps fur­ther to cre­ate a “true” devel­op­ment envi­ron­ment.

  1. Cre­ate a free account on Open­Shift
    1. If you have not seen this, it is pret­ty cool. You can get 3 small gears for free and they can host your node.js appli­ca­tion (among oth­er things!)
  2. When you go through the process on the above page, you will need to install Git ( which is super easy to use and have up and run­ning.
  3. You will also need Ruby to use the rhc gem to inter­act with your Open­Shift appli­ca­tion through com­mand line. I used Ruby 1.9.3-p545 and it worked with only one issue. If you check the box to add Ruby to your PATH, it does not work.
    1. Try >echo %PATH% to check, from com­mand line
    2. If it is not there you can try >set PATH=C:\RUBY193\bin:%PATH% to add it. Make sure you use your actu­al path.
  4. Install the rhc gem and set it up:
  5. Install express and save your­self some time:
  6. You can con­nect your git to your Open­Shift App to make it sim­ple to man­age your code, just make a key and drop it into the Open­Shift Inter­face.

Now, if every­thing is set­up and con­nect­ed prop­er­ly, you can actu­al­ly tail your appli­ca­tion from your con­sole with rhc, add code to your local git and push it to your app and view your appli­ca­tion through your own URL. Mine as an exam­ple: .


var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var host = process.env.OPENSHIFT_NODEJS_IP || "";
var server = app.listen(port, host, function () {
console.log('Example app listening at http://%s:%s', host, port);

After you com­mit your code, the appli­ca­tion auto­mat­i­cal­ly restarts and you should see your Hel­lo World.

All this and I nev­er even got to the spark.js (beyond return vars in the con­sole). That will be com­ing next!