Is there a difference between the following, assuming that we first have called app.set('thePath', thePath)
?
app.use('/', express.static(thePath))
app.use(express.static(thePath))
app.use(express.static(app.get('thePath')))
It seems like (1) and (2) would do the same thing.
As far as I know, in Javascript, if you call a function it evaluates at that time being called, so even if app.get('thePath')
changes or if thePath
changes, all of them would stay the same.
If there is a difference, please let me know what and why it is.
http://expressjs.com/en/4x/api.html#app.use
If path is not specified, it defaults to “/”.
So yes, 1 & 2 are the same. Assuming thePath
is a variable pointing to a valid root directory of static assets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.