DEV Community

Cover image for Using in express-generator.
Abhishek shah
Abhishek shah

Posted on • Updated on

Using in express-generator. has documentation on how to use it with express but it a bit tricky to use with express-generator because the server is created in www file and the io is created in app or server but the use of io is in the router .So how can you use in express-generator ?

Its very simple you can create a new file as mysocket and create instance of io over there and export it.

In the mysocket file.

let socketIo = require('');
let io = socketIo();
let socketApi = {}; = io;
module.exports = socketApi;

In the www file

var server = http.createServer(app);;

So, you can import io from mysocket file into the router and use it.
If you have anything to add you can leave a comment.

Top comments (0)