Express Routing Flashcards

1
Q

What is routing in Express.js?

A

Routing directs requests to the corresponding controllers/methods based on the request’s method and url (path).

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

Difference between middleware and routing

A

Middleware are functions and routing is a process.

Middleware can perform some actions, end the request-response cycle or call the next middleware function.

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

How to implement routing? How do you define routes in Express.js?

A

app.get(“/”,(req,res)=>{ res.send(“Something”) })

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

What are Route Parameters?

A

A route/path might have dynamic part. That’s the Route Parameter.

app.get(‘/users/:userId’)
req.params.userId is a route parameter.

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

What are router object & router methods and how to implement them?

A

const router = express.Router();

router.get(…)

It’s the same as using app.use() but this improves modularity.

To mount the router: app.use(“/api”, router)

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

What are router methods?

A

router.get(path,callback)
router.post(path,callback)
router.put(path,callback)
router.delete(path,callback)

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