After spending several hours working out how to get the basic node.js, socket,io and express demo working I learned a few things. Here is what I learned.
You can verify your installations by entering node -v and npm -v you should see the version numbers for each.
Now I installed socket.io by following the directions on their site. Socket.io handles most of the websocket functions for you and also chooses the best transport methods.
And then I installed the express framework. The express framework takes care of the webserver portion of the project. I used the -g option so that it will work with forever.
Next I install forever so I can close my terminal after starting node.js programs. It also takes care of handling errors and generally keeping the node.js program running.
- Rev version matters. Make sure that the correct version of each program is installed.
- All the programs installed with npm need to be installed in the same directory as the node.js files.
- Most tutorials assume that the basic developer tools are installed, eg. g++.
- The nvm program works for choosing node.js versions to run, but does not tell the socket.io or express packages that an earlier version of node is in use.
- The tutorial I followed can be found at http://psitsmike.com/2011/09/node-js-and-socket-io-chat-tutorial/
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
cd /pick_a_folder #~/Documents/node is a good choice
git clone git://github.com/joyent/node.git
cd node
git checkout v0.10.19 #or latest stable version
./configure
make
make install #finish nodejsEdit: Newer versions of node.js are bundled with npm, so installing npm may not be necessary.
Then install npm to make it easy to add modules to node.js.curl -s https://npmjs.org/install.sh > npm-install.sh | sudo sh npm-install.shnpm install socket.iosudo npm install -g expresssudo npm install forever -gThat concludes the installation of node.js and the necessary modules to create a usable application. Next run a simple chat server or checkout the real-time web based HMI
- You may also be interested in these node.js topics.
- User authentication with Passport
- Redis and node.js
- SSL, node.js and express