0
0
Expressframework~10 mins

User registration flow in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Express and create an app instance.

Express
const express = require('[1]');
const app = express();
Drag options to blanks, or click blank then click option'
Aexpress
Bhttp
Cfs
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' for the import.
Forgetting to import express before creating the app.
2fill in blank
medium

Complete the code to parse incoming JSON data in requests.

Express
app.use([1].json());
Drag options to blanks, or click blank then click option'
AbodyParser
Bexpress
Crouter
Dcors
Attempts:
3 left
💡 Hint
Common Mistakes
Using bodyParser without importing it.
Trying to use router.json() which doesn't exist.
3fill in blank
hard

Fix the error in the route handler to send a JSON response.

Express
app.post('/register', (req, res) => {
  const user = req.body;
  // Save user logic here
  res.[1]({ message: 'User registered successfully' });
});
Drag options to blanks, or click blank then click option'
Ajson
BsendText
CsendFile
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.sendFile() which expects a file path.
Using res.redirect() which sends a redirect response.
4fill in blank
hard

Fill both blanks to create a route that handles GET requests for user data.

Express
app.[1]('/user/:id', (req, [2]) => {
  const userId = req.params.id;
  // Fetch user logic
  res.json({ id: userId });
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cres
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.post() instead of app.get() for GET routes.
Mixing up the order of req and res parameters.
5fill in blank
hard

Fill all three blanks to start the server on port 3000 and log a message.

Express
const PORT = [1];
app.listen(PORT, () => {
  console.log('Server running on port [2]');
  [3];
});
Drag options to blanks, or click blank then click option'
A4000
B3000
Cconsole.log('Ready!')
Dconsole.error('Error!')
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong port number.
Using console.error instead of console.log for normal messages.