D. import express from 'express';
const app = express();
app.get('/data', (req, res) => {
res.json('Hello JSON');
});
app.listen(8080);
Solution
Step 1: Check route method and path
The question asks for a GET route at '/data', so app.get('/data', ...) is correct.
Step 2: Verify response and port
Response should be JSON, so res.json({ message: 'Hello JSON' }) is correct. The server must listen on port 8080.
Step 3: Eliminate alternatives with errors
Alternatives fail due to using POST instead of GET, wrong port like 3000, res.send('string') instead of res.json(object), or res.json('string') instead of object.
Final Answer:
The snippet with app.get('/data'), res.json({ message: 'Hello JSON' }), app.listen(8080) -> Option C
Quick Check:
GET /data + res.json + port 8080 [OK]
Hint: Use app.get + res.json + correct port [OK]
Common Mistakes:
Using POST instead of GET for route
Sending string instead of JSON object
Listening on wrong port number
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.