Chris Mendez in NodeJS, For Developers

Simple Example

<!DOCTYPE html>  
    <title>My App</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Chris Mendez">
    <link rel="shortcut icon" href="/icons/logo-256x256.ico" type="image/">
    <link rel="stylesheet" href="/css/plugins/bootstrap.min.css">
    <!--Bootstrap Theme-->
    <link rel="stylesheet" href="/css/themes/bootstrap.min.css">
    <!--Bootstrap Responsive-->
    <link rel="stylesheet" href="/css/plugins/bootstrap-responsive.min.css">
    <script src="//"></script>
    <!--Google Web Fonts-->
    <script src="//"></script>
    <!--Twitter Bootstrap-->
    <script src="/js/plugins/bootstrap.min.js"></script>
    <script src="/"></script>
      $(document).ready(function() {
          var socket = io.connect('http://localhost');
            //Listen for server handler "news"
            trace( "Listening for 'news' event sent from server.js" );
            socket.on('news', function ( data ){
                trace( "'news' event fired:: " + data )
                trace( "sending data.hello to 'tmpEvent' w/ message " + data.hello );
                socket.emit('tmpEvent', { my: data.hello });



* Title: Simple
* Desc: A simple example
* Modified:
* Notes:

var app = require('http').createServer(handler);  
var fs = require('fs');  
var io = require('').listen(app);

function handler (req, res) {  
  console.log( req, res );
  fs.readFile( __dirname + '/views/index.html', function (err, data)
    if (err) {
      return res.end('Error loading index.html');
    //Write out index.html

//Sockets can be used on top of page rendering
io.sockets.on('connection', function (socket) {  
  //Send data to client (index.html)
  socket.emit('news', { hello: 'world' });
  //Receive data from client (index.html)
  socket.on('tmpEvent', function (data) {
    console.log( "'tmpEvent' fired::", );

app.listen( process.env['app_port'] || 8080 );