Your New Jekyll Site

home

Nodejs Dynmic content and server side javascript

14 Jul 2013

The other day I took a look at NodeJs. NodeJs, is a a composition of 3 parts. A JIT compiler for javascript based on Google’s V8 engine + liviv (an IO event library) + nodes core javascript code. This makes it possible to run javascript on the server. Combining NodeJs with the library Socket.Io, one can maintain an open socket between a client browser and the server. Instead of polling data, the server itself can send the data when data is available without reloading or refreshing the page.

var socket = io.connect();
socket.on('date', function(data){
$('#date').text(data.date);

<div id="date"></div>

The client code above is event driven. ‘date’ is an event sent through the socket. A callback can dynamically update the content of html code dynamically.