1

I was looking through this repository and noticed that the author had declared a variable (io) in app.js:

/* Socket.io Communication */
var io = require('socket.io').listen(server);
io.sockets.on('connection', socket);

He refers to the variable again in public/js/app.js, but doesn't seem to refer to the outer javascript file at all as I would normally expect, so I'm surprised this doesn't result in a ReferenceError.

Could someone please clarify for me what it is about this example that allows this external reference to io to work? Many thanks in advance.

0

1 Answer 1

2

public/js/app.js is client-side javascript and will run in the browser. If you look at index.html, you'll see the client version of socket.io is included at the bottom which defines a global io var.

https://github.com/DanialK/ReactJS-Realtime-Chat/blob/master/public/index.html#L12

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.