Node.js Bug Hunt Hard +35 XP
CORS Not Set
Browser blocks requests from a different origin.
Node.jsFind the bug
1
const app = express();2
app.get('/api/data', (req, res) => res.json(data)); The bug is on line 1
Select the correct fix
Show answer and explanation
Answer: Both A and B work
Browsers enforce CORS. Either use the 'cors' npm package or manually set Access-Control-Allow-Origin headers.
Hint: Browsers block cross-origin requests by default.
What this challenge tests
Bug Hunt in Node.js: cors, security, http-headers.