http request
Sun Apr 06 2025 17:48:52 GMT+0000 (Coordinated Universal Time)
Saved by
@exam3
const http = require('http');
const server = http.createServer((req, res) => {
if (req.url === '/html') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello, World! i am jashwanth reddy</h1>');
} else if (req.url === '/json') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Hello, World! this is jashwanth' }));
} else {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
}
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
content_copyCOPY
Comments