1

Is there something that prevents a console.log() from firing within a socket.io event? I am having a frustrating time with them.

socket.on('messageReceived', function(data) {
    console.log('Server ' + data.msg);
    var clientData = {'msg', 'Hello server'};
    socket.emit('clientResponse', clientData); 
});

in that code my node server receives the client response, but my browser console does not output the console.log. I don't get why... is this normal?

3
  • did your frontend receive clientData? Commented Jun 17, 2018 at 2:20
  • So, what you really mean is "why am I not getting the socket.io message"? Commented Jun 17, 2018 at 4:38
  • no that's not what I meant. I was just confused because I had two browsers open so I thought for sure I was receiving the message but only the console.log was not happening. I understand now that broadcast sends it out to everyone else... Commented Jun 17, 2018 at 11:22

3 Answers 3

1

You can try console.log('a') in console of browser.

If you don't see a, I think you changed level log of console (verbore, info, warn, error) or used filter (you can change it in under of tab console). I don't know what happen if console priint a.

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

2 Comments

I thought that also and checked the level first. I also tried outputting without the data and just a string... i don't get it
Do you test console.log('a') in console, and do you see character 'a' ?
1

I figured out the problem. I was using socket.broadcast.emit from the server instead of broadcast.emit.

I noticed when another browser I had open outputted the console.log.

Thanks everyone who read and put thought into this.

1 Comment

I don't have emit at all. But still console.logs under io.on() does not print
0

I also had console.log not working and I have been spending the weekend debugging it. Nothing worked. (But my server was still running fine) Finally, I became fed up with it and I commented out my entire io.on('connection') code and it still ran.

Then, I went to my client and I saw that I still had my client sending and retrieving to and from my Heroku build that I set when I published the website.

So if you're having issues and nothing that you do is working, check the socket server that you're connecting to with your client.

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.