D
D
DoggoTheKing2017-03-07 14:49:24
JavaScript
DoggoTheKing, 2017-03-07 14:49:24

How to reach the server?

I got acquainted with the node quite recently and after php everything goes around, so don't scold me.
I start the server:

[email protected]: sudo nodejs server.js
Server running at http://localhost:8080/

Server code:
const http = require('http');

const hostname = 'localhost';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

And it is logical that the server was launched locally:
[email protected]: curl localhost:8080
Hello World

When changing the hostname to a domain, the console outputs:
Server running at http://moidomen.com:8080/
Only when accessing moidomen.com:8080/, the browser displays ERR_CONNECTION_TIMED_OUT after a couple of minutes of loading.
What am I doing wrong? :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2017-03-08
@bingo347

hostname server.listen should be IPv4 or IPv6 string
exception 'localhost' - alias for '::1'
callback most likely gets an error with the 1st argument, but you don't process
it if you don't specify hostname or pass '0.0.0.0' to it ' then the port will listen on all network devices

A
Anton Ulanov, 2017-03-07
@antonsr98

Domain Exists? dns or hosts in os know about it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question