0
0
Node.jsframework~10 mins

Serving static files 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'
Ahttp
Bexpress
Cfs
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' to import the framework.
Trying to import 'fs' or 'path' which are Node.js core modules but not Express.
2fill in blank
medium

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

Node.js
app.use(express.static('[1]'));
Drag options to blanks, or click blank then click option'
Apublic
Bstatic
Cassets
Dfiles
Attempts:
3 left
💡 Hint
Common Mistakes
Using a folder name that does not exist.
Forgetting to use express.static middleware.
3fill in blank
hard

Fix the error in the code to correctly serve static files using Express.

Node.js
app.use([1].static('public'));
Drag options to blanks, or click blank then click option'
Apath
Bhttp
Cexpress
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http.static' or 'fs.static' which do not exist.
Forgetting to call the static method on the Express object.
4fill in blank
hard

Fill both blanks to create an Express app that serves static files from 'assets' folder and listens on port 3000.

Node.js
const app = [1]();
app.use([2].static('assets'));
Drag options to blanks, or click blank then click option'
Aexpress
Bhttp
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using different modules for app creation and static serving.
Not calling express as a function to create the app.
5fill in blank
hard

Fill all three blanks to complete the Express server that serves static files from 'static' folder and listens on port 8080.

Node.js
const app = [1]();
app.use([2].static('[3]'));
app.listen(8080);
Drag options to blanks, or click blank then click option'
Aexpress
Cstatic
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' for app creation or static serving.
Incorrect folder name for static files.