We were using code examples from from this github:
Here are a few lessons I learned.
- 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:
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!