0
0
Expressframework~10 mins

User login 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'
Ahttp
Bexpress
Cfs
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' for the app instance.
2fill in blank
medium

Complete the code to parse JSON data from incoming requests.

Express
app.use([1].json());
Drag options to blanks, or click blank then click option'
AbodyParser
Brouter
Cexpress
DcookieParser
Attempts:
3 left
💡 Hint
Common Mistakes
Using bodyParser.json() which is deprecated in recent Express versions.
3fill in blank
hard

Fix the error in the login route handler to correctly access the username from the request body.

Express
app.post('/login', (req, res) => {
  const username = req.body[1];
  res.send(`Hello, ${username}`);
});
Drag options to blanks, or click blank then click option'
A.username
B.name
C.user
D.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'user' or 'name' instead of 'username'.
4fill in blank
hard

Fill both blanks to check if the password matches and send the correct response.

Express
app.post('/login', (req, res) => {
  if (req.body.password [1] storedPassword) {
    res.status([2]).send('Login successful');
  } else {
    res.status(401).send('Unauthorized');
  }
});
Drag options to blanks, or click blank then click option'
A===
B!==
C200
D403
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality operator or wrong status codes like 403 for success.
5fill in blank
hard

Fill all three blanks to create a middleware that logs the request method and URL, then calls next().

Express
function logger(req, res, [1]) {
  console.log(req.[2] + ' ' + req.[3]);
  next();
}
Drag options to blanks, or click blank then click option'
Anext
Bmethod
Curl
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names or accessing properties incorrectly.