Last Updated: February 25, 2016
· pmaoui

Using and Express 3.X on the same port

I'm using CoffeeScript. In my opinion, it should replace javascript :)

If you don't think so, you can convert that code to plain javascript here :

 First we have some dependencies :

express = require 'express'
io = require ''
http =  require 'http'

With Express 3.X you have to explicitely use http and create your server :

server = http.createServer app
io = io.listen server
io.set 'log level', 1
server.listen 80

 Now you can manage all your connections :

io.sockets.on 'connection', (socket)->
    address = socket.handshake.address
    client_ip = address.address
    socket.on 'hello',->
        socket.emit 'hello_you',
            you_are : client_ip

Have a fresh tip? Share with Coderwall community!

Post a tip