Build your own TCP log server with node.js part 2, 23 May 2017

In this part we’ll build the front end in express and connect the

Express :

cd [your project dir]

mkdir logserverFE

cd logserverFE

sudo npm i -g generator-express

sudo npm install -g bower

yo express

? Would you like to create a new directory for your project? No
? Select a version to install: Basic
? Select a view engine to use: Jade
? Select a css preprocessor to use (Sass Requires Ruby): None
? Select a build tool to use: Grunt


And now you have simple server that runs on port 3000, you can point your browser to see it working

npm i --save
npm i jquery --save


we’ll run the server and edit live, recently I like to use atom but any editor will work

edit views/index.jade :

block content
  h1 Hello World!
    input(type='submit', value='Send')


after  ” var app = express(); ” in app.js add:

var socket_io = require(''); = socket_io();'connection', function(client) {
 console.log('Client connected...');
 console.log("Client id : " +;

var routes = require('./routes/index');


add at the end of bin/www :;


and now the server transmit emit messages to all connected browsers …

now we need to transmit incoming tcp messages :

add at the end of bin/www :
// tcp server
  socket.on('data',function(data){'messages', String(data));

And last one for this part :
we add new file public/js/socketio.js :

var url      = window.location.href;
var socket = io.connect(url);
socket.on('connect', function(data) {
  socket.emit('join', 'Hello from client');
socket.on('messages', function(data) {