0
0
Node.jsframework~10 mins

Parsing request body (JSON and form data) in Node.js - 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 the Express framework.

Node.js
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Bhttp
Cpath
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' to import the framework.
Forgetting to put the module name in quotes.
2fill in blank
medium

Complete the code to create a new Express application instance.

Node.js
const app = [1]();
Drag options to blanks, or click blank then click option'
Ahttp
Bexpress
Cserver
Drouter
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call 'http()' instead of 'express()'.
Using a variable that was not defined.
3fill in blank
hard

Fix the error in the middleware setup to parse JSON request bodies.

Node.js
app.use(express.[1]());
Drag options to blanks, or click blank then click option'
Astatic
Burlencoded
Cjson
Drouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'urlencoded' middleware for JSON data.
Forgetting to call the middleware as a function.
4fill in blank
hard

Fill both blanks to parse URL-encoded form data with extended option set to false.

Node.js
app.use(express.[1]({ extended: [2] }));
Drag options to blanks, or click blank then click option'
Aurlencoded
Btrue
Cfalse
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'extended' to true when simple parsing is needed.
Using 'json' middleware for form data.
5fill in blank
hard

Fill all three blanks to create a POST route that reads JSON data from the request body and sends back a message with the user's name.

Node.js
app.post('/hello', (req, res) => {
  const name = req.body.[1];
  res.send(`Hello, ${ [2] }! Your ID is ${req.body.[3].`);
});
Drag options to blanks, or click blank then click option'
Ausername
Bname
Cid
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'username' instead of 'name' for the property.
Forgetting to access 'req.body' before the property.
Mixing up 'id' and 'userId' property names.