O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling WebSocket connections

We will handle WebSocket connections using the socket.io library. This is the most used WebSocket library for the Node.js community.

Now, let's start our WebSocket implementation. Open your index.js file and put this code inside it:

let Rx = require('rx'); let dataSource = require('./data_source'); let services = require('./services')(dataSource); 

For now, we've just imported reactive extensions, our DataSource, and created our services. Now we need to start the server:

let app = require('express')(); let http = require('http').Server(app); let io = require('socket.io')(http); http.listen(3000,()=>console.log('Server listening on port 3000')); 

Here, we create an HTTP server, pass it to the socket.io library, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required