0
0
Expressframework~10 mins

res.set for response headers in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the Content-Type header to 'application/json'.

Express
res.[1]('Content-Type', 'application/json');
Drag options to blanks, or click blank then click option'
Asend
Bset
Cget
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.set, which sends the response body instead of setting headers.
Using res.get, which retrieves headers but does not set them.
2fill in blank
medium

Complete the code to set multiple headers at once using an object.

Express
res.[1]({ 'Cache-Control': 'no-cache', 'X-Powered-By': 'Express' });
Drag options to blanks, or click blank then click option'
Asend
BwriteHead
Cheader
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send which sends the response body, not headers.
Using res.writeHead which is a Node.js method but not typical in Express.
3fill in blank
hard

Fix the error in setting a header by completing the method name correctly.

Express
res.[1]('Authorization', 'Bearer token123');
Drag options to blanks, or click blank then click option'
Aset
BsetHeader
Cheader
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.setHeader which is not the Express method.
Using res.write which is for writing response body.
4fill in blank
hard

Fill both blanks to set the 'Content-Language' header to 'en-US'.

Express
res.[1]('[2]', 'en-US');
Drag options to blanks, or click blank then click option'
Aset
Bsend
CContent-Language
DContent-Type
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Content-Type' instead of 'Content-Language'.
Using res.send instead of res.set.
5fill in blank
hard

Fill all three blanks to set headers 'X-Frame-Options' to 'DENY', 'Strict-Transport-Security' to 'max-age=31536000', and 'Referrer-Policy' to 'no-referrer'.

Express
res.[1]({ [2]: 'DENY', [3]: 'max-age=31536000', 'Referrer-Policy': 'no-referrer' });
Drag options to blanks, or click blank then click option'
Aset
BX-Frame-Options
CStrict-Transport-Security
DContent-Security-Policy
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like res.send or res.write.
Using incorrect header names or misspelling them.