H
H
Hulio_Eglesias2019-09-27 15:50:23
JavaScript
Hulio_Eglesias, 2019-09-27 15:50:23

Can't get an object in another file?

I am trying to access socket instance from another
socket.js file

const IO = require( 'koa-socket-2' );
const io = new IO();
module.exports = {
  io,
}

service.js
const io = require('./../socket').io;
console.log(io); // undefined

Why can't I get this object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-09-27
@Hulio_Eglesias

Try like this:

const IO = require( 'koa-socket-2' );
const io = new IO();
module.exports = {
  io: io,
}

It’s lazy to somehow test, in general, everything is correct, the error is something banal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question