application.use(“/&”,express.static)和app.use(express.sstatic

Is there a difference between app.use("/", express.static) and app.use(express.static)?

本文关键字:express use static sstatic app application      更新时间:2023-09-26

假设我们首先调用了app.set('thePath', thePath),以下之间有区别吗?

  1. app.use('/', express.static(thePath))
  2. app.use(express.static(thePath))
  3. app.use(express.static(app.get('thePath')))

似乎(1)和(2)会做同样的事情。

据我所知,在Javascript中,如果你调用一个函数,它在被调用时会求值,所以即使app.get('thePath')thePath发生了变化,它们都会保持不变。

如果有差异,请告诉我是什么以及为什么。

http://expressjs.com/en/4x/api.html#app.use

如果未指定路径,则默认为"/"。

所以是的,1&2是相同的。假设thePath是指向静态资产的有效根目录的变量。