Complete the code to create a new router instance in Express.
const router = require('express').[1]();
The Router function creates a new router instance for grouping routes.
Complete the code to mount the router under the '/api' namespace.
app.[1]('/api', router);
The use method mounts middleware or routers at a path prefix.
Fix the error in the router code to define a GET route at '/' inside the router.
router.[1]('/', (req, res) => { res.send('Hello from API'); });
The get method defines a handler for GET requests on the router.
Fill both blanks to create a router and export it for use in the main app.
const [1] = require('express').Router(); module.exports = [2];
We create a router named router and export it with the same name.
Fill all three blanks to define a namespaced route that responds with JSON.
const [1] = require('express').Router(); [1].[2]('/status', (req, res) => { res.[3]({ message: 'API is running' }); });
Create a router named router, define a GET route, and respond with JSON using json().
