Blog

Socket.io with Hapi.js

By:
on:

I recently got to work with hapi.js for building an api and I like the Hapi way. To add web-sockets I needed to integrate Socket.io.

Because I couldn't find an up to date explanation on how to do this:

var Hapi = require('hapi');

var server = new Hapi.Server();

server.connection({ 

    host: 'localhost', 

    port: 8000 

});



var io = require("socket.io")(server.listener);



io.on("connection", function (socket) {

    console.log('connected');

    // Do all the socket stuff here.

})



server.start();



In your html do the usual:





    

        

        

    

        

    



KOEN IS HAPPY TO INTRODUCE APPSALOON
APPSALOON BV
Bampslaan 21 box 3.01
3500 Hasselt
Belgium
VAT: BE08 4029 5063
2021 © AppSaloon All Rights Reserved
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram