Complete the code to set the Content-Type header to 'application/json'.
res.setHeader('Content-Type', [1]);
The setHeader method sets the HTTP header. Here, we set the Content-Type to application/json to indicate JSON data.
Complete the code to set the 'Cache-Control' header to 'no-cache'.
res.setHeader('Cache-Control', [1]);
The 'Cache-Control' header controls caching behavior. 'no-cache' tells browsers not to cache the response.
Fix the error in setting multiple headers by completing the method name.
res.[1](200, {'Content-Type': 'text/html', 'X-Custom-Header': 'value'});
The writeHead method sets multiple headers at once along with the status code.
Fill both blanks to set the status code to 404 and the Content-Type header to 'text/plain'.
res.[1](404, [2]);
writeHead sets the status code and headers together. Here, 404 means 'Not Found' and the content is plain text.
Fill all three blanks to set status 200, Content-Type 'application/json', and a custom header 'X-Powered-By' with value 'NodeJS'.
res.setHeader([3], 'NodeJS'); res.[1](200, [2]);
setHeader only.First, setHeader adds a custom header. Then, writeHead sets status and main headers.