0
0
Expressframework~5 mins

express.static middleware - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is express.static middleware used for in Express?

express.static is used to serve static files like images, CSS, and JavaScript files to clients directly from a folder.

Click to reveal answer
beginner
How do you use express.static to serve files from a folder named public?

You use it like this: app.use(express.static('public'));. This tells Express to serve files from the public folder.

Click to reveal answer
intermediate
Can you explain what happens when a client requests /images/logo.png and you have app.use(express.static('public'));?

Express looks inside the public folder for images/logo.png. If it finds the file, it sends it back to the client as a static file.

Click to reveal answer
intermediate
What is the benefit of using express.static middleware instead of manually sending files?

It simplifies serving files, handles caching headers automatically, and improves performance by letting Express manage static content efficiently.

Click to reveal answer
intermediate
How can you serve static files from a virtual path prefix like /static?

You can add a path prefix like this: app.use('/static', express.static('public'));. Then files in public are served under /static URL.

Click to reveal answer
What does express.static middleware do?
AHandles database connections
BServes static files like images and CSS
CParses JSON request bodies
DManages user sessions
How do you serve files from a folder named assets using express.static?
Aapp.use(express.static('assets'));
Bapp.static('assets');
Capp.get('/assets', express.static());
Dexpress.static('assets');
If you want to serve static files under the URL path /files, which code is correct?
Aexpress.static('/files', 'public');
Bapp.use(express.static('/files'));
Capp.get('/files', express.static('public'));
Dapp.use('/files', express.static('public'));
What happens if a requested static file is not found in the folder?
AExpress moves to the next middleware or route
BExpress crashes
CExpress sends a blank response
DExpress automatically creates the file
Which of these is NOT a benefit of using express.static?
AAutomatic caching headers
BSimplifies serving static files
CManages database queries
DImproves performance for static content
Explain how to use express.static middleware to serve static files from a folder and why it is useful.
Think about how websites show images and styles without extra code.
You got /5 concepts.
    Describe how to serve static files under a URL prefix using express.static and what effect this has on the URL paths.
    Imagine putting all images under /static in the URL.
    You got /4 concepts.