Complete the code to define a route that responds to GET requests at the root URL.
app.[1]('/', (req, res) => { res.send('Home page'); });
The get method defines a route for HTTP GET requests, which is used to retrieve data like the home page.
Complete the code to define a route that matches any URL starting with '/user/'.
app.get('/user/[1]', (req, res) => { res.send('User profile'); });
The :id syntax defines a route parameter that matches any value in that part of the URL.
Fix the error in the route order so that the specific route is matched before the general one.
app.get('/[1]', (req, res) => { res.send('Specific route'); }); app.get('/:id', (req, res) => { res.send('General route'); });
The specific route /user/profile must be defined before the general /:id route to match correctly.
Fill both blanks to create a middleware that logs requests only for routes starting with '/api'.
app.[1]('/[2]', (req, res, next) => { console.log('API request:', req.method, req.url); next(); });
Middleware uses app.use and the path /api to apply to all routes starting with '/api'.
Fill all three blanks to define routes so that '/about' shows the about page, and all other paths show a 404 message.
app.get('/[1]', (req, res) => { res.send('About page'); }); app.[2]((req, res) => { res.status(404).send('[3]'); });
The route '/about' is defined with get. The 404 handler uses app.use without a path to catch all unmatched routes and send a 'Page not found' message.