https://www.npmjs.com/package/express
create an http server which will log all urls:
const http = require('http');
// Create the server
const server = http.createServer((req, res) => {
console.log(`Received request: ${req.method} ${req.url}`);
// Set the response header
res.setHeader('Content-Type', 'text/plain');
// Handle different routes
if (req.url === '/' && req.method === 'GET') {
res.writeHead(200);
res.end('Welcome to My HTTP Server!');
} else if (req.url === '/about' && req.method === 'GET') {
res.writeHead(200);
res.end('This is the About Page.');
} else if (req.url === '/data' && req.method === 'GET') {
res.writeHead(200, { 'Content-Type': 'application/json' });
const data = { message: 'Hello, this is some JSON data!' };
res.end(JSON.stringify(data));
} else {
// 404 Not Found
res.writeHead(404);
res.end('Page Not Found');
}
});
// Start the server and listen on port 3000
const PORT = 3000;
server.listen(PORT, () => {
console.log(`Server is running on <http://localhost>:${PORT}`);
});