S
S
squadbrodyaga2020-11-14 19:37:01
Node.js
squadbrodyaga, 2020-11-14 19:37:01

How to make a variable from Socket.io available everywhere?

Hello.
There is such a Socket.io bullshit:

socket.on('Название события', data => {
  const переменная = data
})

and in general there was a need to use a variable from the Socket.io event in another function,
is it possible to somehow make it public? Or do you have to write a function inside the Socket.io event?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VegasChickiChicki, 2020-11-14
@squadbrodyaga

Declare a variable at a higher visibility level and reassign it when you need to.
Or do I need to declare it globally? I'm not a node expert, but there is some kind of global object there, it seems like window on the front, you can try to put it in it.
PS What is it for?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question