Jump to content

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!');

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?


Link to comment
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.

Link to comment
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?

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...