Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8027205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:44:34+00:00 2026-06-04T23:44:34+00:00

This is definitely a very naive question since I am new to node.js. I

  • 0

This is definitely a very naive question since I am new to node.js.

I am just running the very first simple socket.io example from the website:
http://socket.io/#how-to-use

client: index.html:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

server: app.js:

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

From my understanding I assume what will happen is that when server receives a request from the client it will output the data emitted by client {my: 'data'} to the console, which it does, but then it should also send to client the data {hello: 'world'} and when client receives, it is also supposed to log the data to the console? On the terminal console I only see {my: 'data'} for every request. Is the server not sending back data to client correctly or I am looking at the wrong place?

Apparently I think I got confused on some very basic stuff, but when telling the client to do console.log in client side javascript, is the output supposed to be shown on the terminal that executes the server program or something else? If I need to check the output on client console, where should I look for, in the browser?

Hope someone could tell me about this basic concept, I googled a lot but I believe it is just too simple that most just assume people know it so I did not get much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:44:36+00:00Added an answer on June 4, 2026 at 11:44 pm

    On Chrome anywhere in the browser window -> rightclick for menu -> inspect element. This will pop up a window at the bottom of the main window. From the list of tabs ‘Elements’, ‘Resources’, ‘Network’… navigate to ‘Console’. All console logs appear here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is definitely a n00b question but here goes. The way I understand
This isn't a code question for once, but it definitely has me confused. Basically,
Okay this is definitley an easy question and a stupid one but since I
this is my first question in here, and I would like to ask if
I am having a problem very similar to this question here: Can I use
Very inexperienced with Flash, but I hope this is simple enough for someone to
First, I know this is kind of common question, but I could not find
Very confused over this. I've just started learning about pointers and have now decided
I just began having problems with Indy. For some weird reason, even this very
::UPDATE:: LINKS DO NOT EXIST ANYMORE! Very strange indeed, this is definitely a bug!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.