Complete the code to import Express and create an app instance.
const express = require('[1]'); const app = express();
You need to import the 'express' module to create an Express app.
Complete the code to parse incoming JSON data in requests.
app.use([1].json());Express has a built-in JSON parser accessed via express.json().
Fix the error in the route handler to send a JSON response.
app.post('/register', (req, res) => { const user = req.body; // Save user logic here res.[1]({ message: 'User registered successfully' }); });
Use res.json() to send a JSON response to the client.
Fill both blanks to create a route that handles GET requests for user data.
app.[1]('/user/:id', (req, [2]) => { const userId = req.params.id; // Fetch user logic res.json({ id: userId }); });
The route should use app.get() for GET requests, and the second parameter is the response object 'res'.
Fill all three blanks to start the server on port 3000 and log a message.
const PORT = [1]; app.listen(PORT, () => { console.log('Server running on port [2]'); [3]; });
Use port 3000 for the server, log the port number, and print a ready message.
