node.js connection problems

I am new to node.js.

I have a node.js tutorial I am trying to integrate into an existing website application.

The node.js tutorial is a simple chat application.  The tutorial code works.  I can startup the listener by typing the following at a command line:

node index.js

after I press ENTER I get this:

listener on port 3000
At the same location as the index.js file is index.html.  Which means I can now open a browser and enter the following URL:

localhost:3000

This opens the index.html which functions as a chat client.  I can open multiple tabs, each one with a URL of localhost:3000, and anything that is typed is received by the other clients, and vice-versa:

many clients
So up to that point, I know the index.js and index.html files in conjunction with node.js and the installed modules is enough for a basic chat client to work.  And it obviously works.

Now, inside Visual Studio, I open the VERY SAME index.html file and it does not work.  The messages do not get sent or broadcast.

 In the Developer Tools for Chrome (press F12 key) I see this error in the console:

get socket io

I need help understanding why I am getting the error and I need help resolving this.
node_probs.png
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
node.js creates it's own web server.  Visual Studio is not using that web server but uses it's own.  It's not just the index.html page but the underlying server that is important.  In addition, there is nothing in your posted code that shows port 3000 is being used in Visual Studio.
0
Tom KnowltonWeb developerAuthor Commented:
The port is specified in the index.js file:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

Open in new window

0
Tom KnowltonWeb developerAuthor Commented:
When navigating to a page via JavaScript, how can I specify a port to use?

as in:

        document.getElementById("rhs_content").innerHTML = '<object id="temp2" type="text/html" data="NODEJS/nodejs.html" ></object>';

Open in new window


        document.getElementById("rhs_content").innerHTML = '<object id="temp2" type="text/html" data="NODEJS/nodejs.html:3000" ></object>';

Open in new window


does that work?

NODEJS/nodejs.html:3000




the nodejs.html page is being injected into a div with id = "rhs_content"
0
Dave BaldwinFixer of ProblemsCommented:
If it works at all, the syntax would be: NODEJS:3000/nodejs.html where NODEJS is the name of the node.js server.  Port numbers always come right after the domain or server name.  You can test to see if it will work by putting "NODEJS:3000/nodejs.html" in your browser address bar.

Note that this will not work remotely because NODEJS does not have a DNS entry so the browser can look it up.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.