Loading

Quipoin Menu

Learn • Practice • Grow

node-js / Serving HTML Files
mcq
Direction: Choose the correct option

Q1.

How would you serve an HTML file in raw Node.js?
A. Send the HTML string directly
B. Use `res.sendFile()`
C. All of the above
D. Read the file with `fs` and write to response
Direction: Choose the correct option

Q2.

What `Content-Type` header should be set when serving HTML?
A. application/html
B. text/xml
C. text/html
D. text/plain
Direction: Choose the correct option

Q3.

Why should you use `res.writeHead()` or `res.setHeader()` before sending data?
A. To improve performance
B. It doesn't matter
C. Because headers must be sent before the body
D. Headers are automatically set
Direction: Choose the correct option

Q4.

What is a common issue when reading HTML files synchronously in a server?
A. Files cannot be read
B. It's not allowed
C. It blocks the event loop for all clients
D. It's faster
Direction: Choose the correct option

Q5.

How can you serve HTML files asynchronously without blocking?
A. Use `fs.readFileSync`
B. Use `fs.createReadStream` and pipe
C. Use `fs.readFile` with a callback
D. Both A and B