const http = require('http'); // Loads the http module
http.createServer((req, res) => {
// 1. Tell the browser everything is OK (Status code 200), and the data is in plain text
res.writeHead(200, {
'Content-Type': 'text/plain'
});
// 2. Write the announced text to the body of the page
res.write('Hello, World!\n');
// 3. Tell the server that all of the response headers and body have been sent
res.end();
}).listen(2000); // 4. Tells the server what port to be on
console.log("server is running on port : ",2000);
- The HTTP module is a Node.js core module (a module included in Node.js's source, that does not require installing additional resources).
- The HTTP module provides the functionality to create an HTTP server using the HTTP.createServer() method.
Comments
Post a Comment