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/');
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter