Answer the question
In order to leave comments, you need to log in
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/
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}/`);
});
[email protected]: curl localhost:8080
Hello World
Server running at http://moidomen.com:8080/
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question