Bird
0
0

You want to serve static files from the public folder but under the URL path prefix /static. Which code correctly achieves this?

hard📝 Application Q15 of 15
Node.js - HTTP Module
You want to serve static files from the public folder but under the URL path prefix /static. Which code correctly achieves this?
Aapp.use('/static', express.static('public'))
Bapp.use(express.static('/static/public'))
Capp.use('/public', express.static('static'))
Dapp.get('/static', express.static('public'))
Step-by-Step Solution
Solution:
  1. Step 1: Understand URL prefix with express.static

    To serve static files under a URL prefix, pass the prefix as the first argument to app.use, then the static middleware.
  2. Step 2: Evaluate each option

    app.use('/static', express.static('public')) correctly uses app.use('/static', express.static('public')). Others either misuse paths or methods.
  3. Final Answer:

    app.use('/static', express.static('public')) -> Option A
  4. Quick Check:

    URL prefix with app.use('/prefix', express.static(folder)) = A [OK]
Quick Trick: Use app.use('/prefix', express.static('folder')) for URL prefix [OK]
Common Mistakes:
  • Putting URL prefix inside express.static argument
  • Using app.get instead of app.use for static files
  • Mixing folder and URL prefix names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes