const http = require('http');
const server = http.createServer((req, res) => {
console.log(req.url, req.method, req.headers);
//process.exit();
res.setHeader('Content-Type', 'test/html');
res.write('<html>');
res.write('<head><title>My first page</title></head>');
res.write('<body><h1>Hello from my Node.js Server</h1></body>');
res.write('</html>');
res.end();
});
server.listen(3000);
Im expecting the page to say Hello form my Node.js but instead nothing is recieved
New contributor
Muhammad Wajeeh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Because content type is not valid,
'Content-Type', 'test/html'
should be
'Content-Type', 'text/html'
Valid Content-Types can be found here https://www.iana.org/assignments/media-types/media-types.xhtml