Node.js - HTTP ModuleWhich of the following is the correct syntax to send a 201 status with a JSON response in Express?Ares.json(201, { message: 'Created' })Bres.sendStatus(201, { message: 'Created' })Cres.status(201).send('Created')Dres.status(201).json({ message: 'Created' })Check Answer
Step-by-Step SolutionSolution:Step 1: Understand chaining methodsres.status(201) sets status, then .json() sends JSON data.Step 2: Check other options for syntax errorsres.sendStatus() does not accept data; res.json() does not take status as first argument; res.status(201).send('Created') sends plain text, not JSON.Final Answer:res.status(201).json({ message: 'Created' }) -> Option DQuick Check:Set status then send JSON with .json() [OK]Quick Trick: Chain res.status(code).json(data) to send JSON with status [OK]Common Mistakes:Passing status code as first argument to res.json()Using res.sendStatus() with data argumentUsing res.send() with string for JSON response
Master "HTTP Module" in Node.js9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Node.js Quizzes Child Processes - fork for Node.js child processes - Quiz 2easy Cluster Module - Load balancing between workers - Quiz 4medium Debugging and Profiling - Console methods beyond log - Quiz 14medium Debugging and Profiling - Console methods beyond log - Quiz 13medium Debugging and Profiling - Node.js built-in debugger - Quiz 5medium Error Handling Patterns - Graceful shutdown on errors - Quiz 4medium HTTP Module - Serving static files - Quiz 7medium Timers and Scheduling - Event loop phases and timer execution - Quiz 2easy Timers and Scheduling - setInterval and clearInterval - Quiz 2easy URL and Query String Handling - Why URL parsing matters - Quiz 1easy