Font size
WorksheetsBED AY25S2 Formative: npm, http routes
Total questions: 12
Worksheet time: 4mins
Which line of code correctly initializes an Express application instance?
const app = express.create();
const app = express()
Which code is used to create a route that handles an HTTP POST request to the path /users?
app.get('/users',
(req, res) => {...})
app.put('/users',
(req, res) => {...})
app.delete('/users',
(req, res) => {...})
app.post('/users',
(req, res) => {...})
In the route /items/:id, how do you access the value of the dynamic route :id?
For the request /users?status=active,
how do you access the value of the query parameter?
req.params.status
req.query.status
req.body.status
req.url.status
Which method starts the Express server and binds it to a specified port?
Which npm command installs the express package
and adds it as a production dependency to package.json?
npm add express
npm install --save express
npm get express
npm install express
To execute a custom script named "deploy" in your package.json, which npm command must you use?
What is arr3?
const arr1 = [1, 2]
const arr2 = [3, 4]
const arr3 = [...arr1, ...arr2];
What is filtered?
const numbers = [1, 2, 3, 4, 5];
const filtered = numbers.filter(num => num <= 1)
What is the purpose of wrapping code in a try-catch block in Express?
What is products2?
const products = [{id: 1, name: 'Laptop'}, {id: 2, name: 'Mouse'}];
const products2 = products.find(p => p.id === 1)
[{"id": 1, "name": "Laptop"}]
{}
[{}]
How do I feel right now?
