
Node.js and Socket.IO
Node.js is pretty awesome! I encountered the asynchronous JavaScript based web server platform when working on a specialization about (network) communication. As a demo I wrote a basic web server vote/polling system where people can vote on one page and see the polls rise and fall on another page. Data sending and retrieval was almost on the fly available through the use of Socket.IO’s “websockets”.
Of course this is a demo which means that there is still (a lot of) room for improvements. I’ve used to save the statistic values because it was a mandatory part of the assessment.
Working
So how does the Node.js application work? To start the application index.js has to be run trough node.js command prompt.
When a resource is requested the following process starts. Pathname is everything that comes after localhost:1337/ ( localhost:1337/[pathname]).
When a websocket connection is established.
When the webserver receives new form data.
The HTML pages
Conclusion & Resources
I hope this post gives a nice overview of the vote/poll application. Node.js and Socket.IO are pretty cool technologies that I will surely use in future projects!
The Node Beginners Book was a very useful resource for getting started with Node.js.

5 Comments
Hi Barry!
I have a question. I am new to Node.js. You said if the values are changing (after a vote) the graph will also going to change. But the graph changes only when I refresh the page. What is the problem?
Best regards,
Daniel
Great post!
Thanks Barry. I’ll give this another try tonight.
Great example. I am having a little bit of difficulty getting it to write to the json file. Here is the error. Are there any node modules needed other than the serial.io? Any idea why the failure below?
Thanks!
You only need Socket.io to run this demo. After running the demo at my work computer I’ve encountered the same error. I think it has something to do with an updated version of Node.js. Anyway I’ve also found a solution.
In statistics.js change the following.
Recent Posts
Sep 30, 2013
Jan 10, 2013
Dec 25, 2012
Dec 06, 2012
Recent Comments
Archives
Categories