0
0
Expressframework~10 mins

express.static middleware - Interactive Code Practice

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

Complete the code to serve static files from the 'public' folder using Express.

Express
app.use([1]('public'));
Drag options to blanks, or click blank then click option'
Aexpress.urlencoded
Bexpress.json
Cexpress.Router
Dexpress.static
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.json instead of express.static
Forgetting to call the function with the folder name
Using express.Router which is for routing, not static files
2fill in blank
medium

Complete the code to mount the static middleware at the '/assets' path.

Express
app.use('/assets', [1]('public'));
Drag options to blanks, or click blank then click option'
Aexpress.static
Bexpress.json
Cexpress.Router
Dexpress.urlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.json or express.urlencoded instead of express.static
Not specifying the mount path correctly
3fill in blank
hard

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

Express
app.use(express.static([1]));
Drag options to blanks, or click blank then click option'
A'/static'
B'static'
Cpath.join(__dirname, 'static')
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using a relative path string without __dirname
Using a string with a leading slash which is not a folder path
4fill in blank
hard

Fill both blanks to create a static middleware that serves files from the 'assets' folder and sets a max age of 1 day.

Express
app.use(express.static([1], { maxAge: [2] }));
Drag options to blanks, or click blank then click option'
Apath.join(__dirname, 'assets')
B1000
C86400000
D'assets'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a relative string path instead of absolute
Setting maxAge to 1000 which is only 1 second
5fill in blank
hard

Fill all three blanks to create an Express app that serves static files from 'public', parses JSON bodies, and listens on port 3000.

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

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

app.listen([3], () => {
  console.log('Server running');
});
Drag options to blanks, or click blank then click option'
Aexpress.static
Bjson
C3000
Durlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.urlencoded instead of express.json for JSON parsing
Forgetting to specify the port number as a number