0
0
Expressframework~10 mins

Built-in middleware (json, urlencoded, static) 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 use Express built-in middleware for parsing JSON bodies.

Express
const express = require('express');
const app = express();

app.use(express.[1]());

app.post('/data', (req, res) => {
  res.json(req.body);
});
Drag options to blanks, or click blank then click option'
Ajson
Burlencoded
Cstatic
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Using urlencoded middleware for JSON data
Forgetting to call the middleware as a function
Using static middleware for parsing bodies
2fill in blank
medium

Complete the code to use Express built-in middleware for parsing URL-encoded bodies.

Express
const express = require('express');
const app = express();

app.use(express.[1]({ extended: false }));

app.post('/form', (req, res) => {
  res.send(req.body);
});
Drag options to blanks, or click blank then click option'
Atext
Bjson
Cstatic
Durlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using json middleware for URL-encoded data
Not passing the options object with extended property
Using static middleware for parsing bodies
3fill in blank
hard

Fix the error in the code to serve static files from the 'public' folder.

Express
const express = require('express');
const app = express();

app.use(express.[1]('public'));

app.listen(3000);
Drag options to blanks, or click blank then click option'
Astatic
Burlencoded
Cjson
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Using json or urlencoded middleware for static files
Forgetting to specify the folder name
Not calling the middleware as a function
4fill in blank
hard

Fill both blanks to parse JSON and URL-encoded data in Express.

Express
const express = require('express');
const app = express();

app.use(express.[1]());
app.use(express.[2]({ extended: true }));
Drag options to blanks, or click blank then click option'
Ajson
Burlencoded
Cstatic
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of middleware
Using static middleware instead of parsing middleware
Not passing options to urlencoded middleware
5fill in blank
hard

Fill all three blanks to set up Express with JSON parsing, URL-encoded parsing, and static file serving from 'assets'.

Express
const express = require('express');
const app = express();

app.use(express.[1]());
app.use(express.[2]({ extended: false }));
app.use(express.[3]('assets'));
Drag options to blanks, or click blank then click option'
Ajson
Burlencoded
Cstatic
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong middleware for static files
Not passing options to urlencoded middleware
Forgetting to call middleware functions