Middlewares-and-Routers Flashcards

1
Q

Question

A

Answers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you use middleware?

A

app.use(middlewareName())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create middleware?

A

const middlewareName = (req, res, next) => { next()}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you create a router?

A

const router = express.Router()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you add HTTP methods to your router?

A

router.route(‘subURL’).method(controller).method(controller)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you use a router?

A

app.use(‘URL’,router)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are param middlewares?

A

They are middlewares that run for a URL, only if a specific parameter exists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create a param middleware?

A

const middleware = (req, res, next, val) => {//val is the param value next()}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you use the param middleware?

A

By assigning it to a router e.g. router.param(‘url’, middleware)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you chain middlewares for a single route?

A

Router.method(middleware, middleware, middleware)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly