Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

export socket io connection

let io;

module.exports = {
  init: (server) => {
    io = require('socket.io').listen(server); io.origins('*:*');
    return io;
  },
  get: () => {
    if (!io) {
      throw new Error("socket is not initialized");
    }
    return io;
  }
};
Comment

export socket io connection

const app = require('../app');
const http = require('http');

/**
 * Get port from environment and store in Express.
 */

const port = '3015';
app.set('port', port);

/**
 * Create HTTP server.
 */

const server = http.createServer(app);
const io = require('./socket.js').init(server);

io.on('connection', (socket) => {
  console.log('Connection success', socket.id);
  socket.on('disconnect', () => {
    console.log('Connection disconnected', socket.id);
  });
}
Comment

export socket io connection

const io = require('./socket.js').get();
Comment

PREVIOUS NEXT
Code Example
Javascript :: pdfjs get all the text present 
Javascript :: vue js convert string to html 
Javascript :: date range query knex 
Javascript :: sticky sessions 
Javascript :: last element of array 
Javascript :: math js 
Javascript :: open ai gym 
Javascript :: byte to integer js 
Javascript :: angular start command 
Javascript :: javascript unknown number of parameters 
Javascript :: deno vs nodejs 
Javascript :: javascript count number of clicks limit 
Javascript :: experss cookie session 
Javascript :: mdn object assign 
Javascript :: decode raw data to string nodejs 
Javascript :: get window size on resizing 
Javascript :: loading react 
Javascript :: using datatable 
Javascript :: Next js Linking example 
Javascript :: Update matched key values in two JavaScript objects 
Javascript :: how to go to last page after authentication 
Javascript :: cut and paste element js 
Javascript :: Creating with the custom hook in react 
Javascript :: javascript mutation observer 
Javascript :: scroll up own 
Javascript :: adb.exe: more than one device/emulator react native 
Javascript :: open new window in java script 
Javascript :: how to set expire time of jwt token in node js 
Javascript :: adding methods to objects javascript 
Javascript :: string length js 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =