Jump to content
Sign in to follow this  
Narcis

Initiate the Node.js File. Ports problem?

Recommended Posts

I try to learn Node.js. I followed that tutorial: https://www.w3schools.com/nodejs/nodejs_get_started.asp

As the tutorial says, I created a file: myfirst.js with that content: 

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Hello World!');
}).listen(8080);

I have a Mac. I open the Terminal and reach that file: Your Name>node myfirst.js

I open a browser and type the address: http://localhost:8080 And I see nothing. Safari says: Safari can't connect to the Server. Similar with other browsers. 

What is wrong?

 

Share this post


Link to post
Share on other sites

Did node say anything after that? Any errors?

Did you keep the terminal open? Node runs as a process inside that, so if you close it, no more server.

Share this post


Link to post
Share on other sites

I still do not understand very well that concept of server and "Node running as a process inside the terminal". But thank you, now I can continue and perhaps I will have a more clear idea when I finish the tutorial?

Share this post


Link to post
Share on other sites

You might do, although you may want to look up terms you're unfamiliar with.

If you have any further questions about it, you're always free to ask here.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...