const http = require('http'); // Create an HTTP server const server = http.createServer((req, res) => { // Set the response HTTP header with HTTP status and Content type res.writeHead(200, { 'Content-Type': 'text/plain' }); // Get the URL path const path = req.url; // Respond with different messages based on the URL path if (path === '/') { res.end('Hello, Node.js!'); } else if (path === '/about') { res.end('About Us'); } else if (path === '/contact') { res.end('Contact Us'); } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('404 Not Found'); } }); // The server listens on port 3000 server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); });