wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

BED AY25S2 Formative: npm, http routes

Total questions: 12

Worksheet time: 4mins

Name
Class
Date
1.


Which line of code correctly initializes an Express application instance?

a)
const app = new express();
b)

const app = express.create();

c)
const app = express.init();
d)

const app = express()

2.

Which code is used to create a route that handles an HTTP POST request to the path /users?

a)

app.get('/users',
(req, res) => {...})

b)

app.put('/users',
(req, res) => {...})

c)

app.delete('/users',
(req, res) => {...})

d)

app.post('/users',
(req, res) => {...})

3.

In the route /items/:id, how do you access the value of the dynamic route :id?

a)
req.body.id
b)
req.params.id
c)
req.query.id
d)
req.headers.id
4.

For the request /users?status=active,
how do you access the value of the query parameter?

a)

req.params.status

b)

req.query.status

c)

req.body.status

d)

req.url.status

5.

Which method starts the Express server and binds it to a specified port?

a)
app.start()
b)
server.run()
c)
app.listen()
d)
express.init()
6.

Which npm command installs the express package
and adds it as a production dependency to package.json?

a)

npm add express

b)

npm install --save express

c)

npm get express

d)

npm install express

7.

To execute a custom script named "deploy" in your package.json, which npm command must you use?

a)
npm run deploy
b)
npm start deploy
c)
npm exec deploy
d)
npm deploy
8.

What is arr3?
const arr1 = [1, 2]
const arr2 = [3, 4]
const arr3 = [...arr1, ...arr2];

a)
[1, 3, 4]
b)
[2, 3, 4]
c)
[1, 2, 3, 4]
d)
[1, 2, 4]
9.

What is filtered?
const numbers = [1, 2, 3, 4, 5];
const filtered = numbers.filter(num => num <= 1)

a)
[1]
b)
[4, 5]
c)
[2, 3]
d)
[]
10.


What is the purpose of wrapping code in a try-catch block in Express?

a)
To improve code readability and maintainability.
b)
To increase the performance of the application.
c)
To automatically log all requests made to the server.
d)
To handle errors gracefully and prevent application crashes.
11.

What is products2?
const products = [{id: 1, name: 'Laptop'}, {id: 2, name: 'Mouse'}];
const products2 = products.find(p => p.id === 1)

a)
{"id": 1, "name": "Laptop"}
b)

[{"id": 1, "name": "Laptop"}]

c)

{}

d)

[{}]

12.

How do I feel right now?