Performance: Route parameters
Route parameters affect server-side request handling speed and can indirectly impact page load speed by controlling how quickly the server responds.
app.get('/user/:id/profile/:section', async (req, res) => { const data = await fetchUserData(req.params.id); res.send(data); });
app.get('/user/:id/profile/:section', (req, res) => { /* heavy synchronous processing */ });
| Pattern | Server Processing | Blocking | Response Time Impact | Verdict |
|---|---|---|---|---|
| Synchronous heavy processing in route handler | High CPU use | Blocks event loop | Increases response time significantly | [X] Bad |
| Asynchronous non-blocking route handler | Low CPU use | No blocking | Fast response time | [OK] Good |
req.params represent in an Express route handler?/user/:id.req.params as an object with keys matching parameter names.postId in Express?: before the parameter name to mark it as dynamic./:postId correctly. Options A, B, and D use incorrect syntax for parameters./user/42?
app.get('/user/:id', (req, res) => {
res.send(`User ID is ${req.params.id}`);
});:id, so req.params.id will hold the value from the URL./user/42 sets id to '42', so the response sends 'User ID is 42'.app.get('/product/:productId', (req, res) => {
const id = req.params.product;
res.send(`Product ID: ${id}`);
});
What is the problem with this code?productId, so req.params will have a key named productId.req.params.product, which does not exist, so id will be undefined./order/123/item/456 to get both orderId and itemId. Which route definition and parameter access is correct?:orderId and :itemId to capture both values from the URL.req.params.orderId and req.params.itemId to get the values inside the handler.Pass the test and this pattern moves unknown