0
0
Expressframework~20 mins

User registration flow in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express User Registration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when a user submits valid registration data?
Consider this Express route handling user registration. What response does the server send when the user provides valid data?
Express
app.post('/register', (req, res) => {
  const { username, password } = req.body;
  if (!username || !password) {
    return res.status(400).json({ error: 'Missing fields' });
  }
  // Simulate saving user
  res.status(201).json({ message: `User ${username} registered successfully` });
});
A{"message":"User alice registered successfully"}
B{"error":"Missing fields"}
C500 Internal Server Error
DEmpty response
Attempts:
2 left
💡 Hint
Check what happens when both username and password are present.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in this Express registration route?
Identify the option that contains a syntax error preventing the server from running.
Express
app.post('/register', (req, res) => {
  const { username, password } = req.body
  if (!username || !password) {
    res.status(400).json({ error: 'Missing fields' });
  } else {
    res.status(201).json({ message: `User ${username} registered` });
  }
});
AUsing backticks incorrectly in template string
BUsing res.status(400).json without return statement
CMissing semicolon after destructuring assignment
DMissing closing parenthesis in app.post call
Attempts:
2 left
💡 Hint
Look for unmatched parentheses or brackets.
state_output
advanced
2:00remaining
What is the value of 'users' array after two successful registrations?
Given this Express code snippet, what does the 'users' array contain after two POST requests with valid data?
Express
const users = [];
app.post('/register', (req, res) => {
  const { username, password } = req.body;
  if (!username || !password) {
    return res.status(400).json({ error: 'Missing fields' });
  }
  users.push({ username, password });
  res.status(201).json({ message: `User ${username} registered` });
});
A[{ username: 'alice', password: '123' }, { username: 'bob', password: '456' }]
B[]
C[{ username: 'alice', password: '123' }]
D[{ username: 'bob', password: '456' }, { username: 'alice', password: '123' }]
Attempts:
2 left
💡 Hint
The users array collects each valid registration in order.
🔧 Debug
advanced
2:00remaining
Why does this registration route cause the server to hang?
Examine the code and find why the server does not respond to requests.
Express
app.post('/register', (req, res) => {
  const { username, password } = req.body;
  if (!username || !password) {
    res.status(400).json({ error: 'Missing fields' });
  }
  // Missing else or return here
  res.status(201).json({ message: `User ${username} registered` });
});
AThe server crashes due to missing middleware
BThe server never sends a response causing a timeout
CThe server throws a syntax error
DThe server sends two responses causing an error
Attempts:
2 left
💡 Hint
Check if res methods are called more than once per request.
🧠 Conceptual
expert
2:00remaining
Which middleware is essential to parse JSON body in Express user registration?
Without this middleware, req.body will be undefined in the registration route. Which one is it?
Aexpress.cookieParser()
Bexpress.json()
Cexpress.static()
Dexpress.urlencoded()
Attempts:
2 left
💡 Hint
It parses incoming JSON payloads.