For our Spatial Media class, we are learning Node.js (http://nodejs.org/) and using it to connect web-based inputs and outputs via Spacebrew (http://docs.spacebrew.cc/). I had a tricky time with it, mainly because I know nothing about servers, javascript, Node.js or the inner-workings of my cat’s mind… but that’s another story.
We were using code examples from from this github:
https://github.com/jefftimesten/SpatialMedia/tree/master/Week_08
Here are a few lessons I learned.
- In layman’s terms, Node.js is a way to use javascript to make efficient servers so you don’t have to run things like Apache. I’m still hazy on the server concept, but this article is a good start: http://en.wikipedia.org/wiki/Nodejs
- To install Node.js, go to http://nodejs.org/
- Node.js applications can be written/edited in any plain text editor (I used TextWrangler).
- The .js applications are compiled/run via Terminal. You must navigate into the appropriate folder and run the “app.js” or “server.js” (those are the common server app names) by entering the following command:
$ node app.js Note: “$” should not be typed into the terminal—it’s just a way to indicate something is a Terminal command.
- For the github examples used in our class, you need to install Express — a web application framework for Node.
- Node.js uses npm (Node Packaged Modules: https://npmjs.org/) to install “plugins” or “libraries” — the things that help it run.
- You can install Express locally (into the folder where your code lives so it only works for code in that folder) or globally (so after one installation Express will work for any file on the computer).
- To install locally (via Terminal), navigate into your folder and enter:
$ npm install express
- To install globally, enter: $ npm install -g npm Note: If you are using a Mac and get errors with the above global install command, try adding “sudo” in front of it: $ sudo npm install -g express
- After installing Express, my node-spacebrew example didn’t run because I was missing a “ws” websocket Spacebrew uses (check out this article about websockets: http://en.wikipedia.org/wiki/WebSocket). To install the “ws” websocket via Terminal, enter $ npm install ws
- Once everything is installed, open Spacebrew by going here:
http://labatrockwell.github.io/spacebrew/admin/admin.html?server=sandbox.spacebrew.cc
I had trouble getting the file to run until Spacebrew was open
- Run the example in Terminal by entering: $ node app.js
- You should see your “publisher” appear in the Spacebrew window. I changed the name of my publisher to “It Works!” by opening the app.js file in TextWrangler and changing:
var name = “It works!”
var description = “Yuliya’s Node test!”;
P.S. Thank you Andy Sigler for helping figure this out!






