Homework & Coding Practice
Homework/Practice Coding Assignment (20-min)
const http = require('http'); const server = http.createServer((req, res) => { console.log(`Request Method: ${req.method}, URL: ${req.url}`); if (req.url === '/') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Welcome to the Home Page'); } else if (req.url === '/about') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('This is the About Page'); } else if (req.url === '/contact') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Contact us at [email protected]'); } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('404 Not Found'); } }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); });
//bash node multiRouteServer.js
Expected Outcomes
Last updated