Building a node.js app using Express & Socket.IO
Here are some notes for my node.js workshop that you can use to follow along during and after the talk. Together, we’ll build the server-side portion of a simple app called UserSpy using two popular node.js frameworks: express and socket.io.
The very first thing you’ll want to do is install node.js on your local machine. Click the Download button on the website and choose the correct package for your platform.
Ensure installation was successful by running
node -vin a terminal. It should print out the version of node installed.
When developing node apps, you’ll need to restart the app after every change. To automate this, install nodemon:
sudo npm install nodemon -g
From now on, instead of running apps using
nodeyou can use
nodemonto get the auto-restart functionality.
Grab the project
Make a clone of the userspy repository:
git clone https://github.com/ammmir/userspy
Although node has a rich core API, there are thousands of modules available at the official npm registry. A node app declares its module dependencies in a file called package.json. Use
npm(included in your node installation) to install them:
Finally, run the app:
If you followed all the steps above, you’ll see something like this:
5 Jun 15:11:57 - [nodemon] v0.6.12 5 Jun 15:11:57 - [nodemon] watching: /Users/amir/src/userspy 5 Jun 15:11:57 - [nodemon] starting `node server.js` UserSpy server started.
Now we’re ready to start coding :)Posted on 8 June 2012