Computer scienceBackendNode.jsCore ConceptsInternal modulesHTTP serverhttp module

Routing

Organized Node.js routing example

Report a typo

Rearrange this code for better code organization. Place related parts of the code together and follow best practices of routing in Node code structure.

Indent the answer where necessary for it to be functional.
Reorder lines using drag or arrows. Adjust indentation with left buttons
                console.log(`Server is running at http://localhost:${port}`);
              
                }
              
                res.writeHead(404, { 'Content-Type': 'text/plain' });
              
                res.end('404 Not Found');
              
                res.writeHead(200, { 'Content-Type': 'text/plain' });
              
                const server = http.createServer((req, res) => {
              
                const port = 3000;
              
                });
              
                const url = req.url;
              
                const http = require('http');
              
                });
              
                } else {
              
                server.listen(port, () => {
              
                if (url === '/') {
              
                res.end('Welcome to the Home Page!');
              
___

Create a free account to access the full topic