Bird
0
0

Which of the following is the correct syntax to serve static files from a folder named public using Express?

easy📝 Syntax Q12 of 15
Node.js - HTTP Module
Which of the following is the correct syntax to serve static files from a folder named public using Express?
Aapp.static('public')
Bapp.use(express.static('public'))
Cexpress.use.static('public')
Dapp.getStatic('public')
Step-by-Step Solution
Solution:
  1. Step 1: Recall Express static middleware syntax

    The correct way is to call app.use(express.static('folderName')) to serve static files.
  2. Step 2: Check each option

    Only app.use(express.static('public')) uses the correct method and syntax. Others are invalid or do not exist in Express.
  3. Final Answer:

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

    Correct static serving syntax = B [OK]
Quick Trick: Use app.use with express.static and folder name [OK]
Common Mistakes:
  • Using app.static instead of app.use(express.static)
  • Calling express.use.static which is invalid
  • Trying app.getStatic which does not exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes