-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbasicHttpServer.js
22 lines (19 loc) · 913 Bytes
/
basicHttpServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Importing the standart library module HTTP for creating a HTTP server
const http = require("http");
//Setting the hostname and port number for the server to listen
const hostname = "127.0.0.1";
const port = 3000;
// The createServer() method of http creates a new HTTP server and returns it
const server = http.createServer((req, res) => {
// Set the statusCode property to 200, to indicate a successful response
res.statusCode = 200;
// Set the Content-Type header
res.setHeader("Content-Type", "text/plain");
// Close the response, adding the content as an argument to end()
res.end("Hello NodeJS");
});
// The server is set to listen on the specified port and host name
server.listen(port, hostname, () => {
// When the server is ready, the callback function is called, in this case informing us that the server is running
console.log(`Server running at http://${hostname}:${port}`);
});