Bird
0
0

What response will a browser display when accessing this Node.js server?

medium📝 component behavior Q4 of 15
Node.js - HTTP Module
What response will a browser display when accessing this Node.js server?
const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('<h1>Welcome</h1>');
});
server.listen(3000);
AA webpage showing a heading with the text 'Welcome'.
BA plain text response displaying '<h1>Welcome</h1>'.
CAn error message because the content type is incorrect.
DA blank page with HTTP status 404.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze headers

    The response header sets 'Content-Type' to 'text/html', so the browser interprets the body as HTML.
  2. Step 2: Analyze body

    The body contains HTML markup for a heading: '<h1>Welcome</h1>'.
  3. Final Answer:

    The browser renders a heading with 'Welcome'. -> Option A
  4. Quick Check:

    Content-Type 'text/html' renders HTML [OK]
Quick Trick: Content-Type 'text/html' renders HTML tags [OK]
Common Mistakes:
  • Assuming HTML tags show as plain text
  • Confusing content types
  • Expecting an error due to HTML tags

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes