0
0
Expressframework~10 mins

Why serving static files matters in Express - Test Your Understanding

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(express.[1]('public'));
Drag options to blanks, or click blank then click option'
Arouter
Bjson
Cstatic
Durlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.json() instead of express.static()
Forgetting to specify the folder name
Using app.router which is for routes, not static files
2fill in blank
medium

Complete the code to set up Express to serve static files from a folder named 'assets'.

Express
app.use(express.static('[1]'));
Drag options to blanks, or click blank then click option'
Aassets
Bstatic
Cpublic
Dfiles
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong folder name like 'public' when files are in 'assets'
Leaving the folder name empty
Using a file name instead of a folder name
3fill in blank
hard

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

Express
app.use(express.[1]('static'));
Drag options to blanks, or click blank then click option'
Astatic
Brouter
Cjson
Durlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.router which is for routing, not static files
Using express.json which parses JSON bodies
Using express.urlencoded which parses URL-encoded bodies
4fill in blank
hard

Fill both blanks to serve static files from 'public' folder and mount it at '/static' URL path.

Express
app.use('[1]', express.[2]('public'));
Drag options to blanks, or click blank then click option'
A/static
B/public
Cstatic
Drouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/public' as the URL path when the question asks for '/static'
Using 'router' instead of 'static' middleware
Omitting the URL path and mounting directly
5fill in blank
hard

Fill all three blanks to create a static server with Express that serves files from 'assets' folder at '/files' URL path and logs a message when server starts.

Express
app.use('[1]', express.[2]('[3]'));

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
Drag options to blanks, or click blank then click option'
A/files
Bassets
Cstatic
D/assets
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up URL path and folder name
Using 'router' instead of 'static' middleware
Not matching folder name with actual static files location