【发布时间】:2015-10-04 04:35:56
【问题描述】:
有什么区别,我应该使用哪个?我的目标是简单地提供静态 html 页面和文件。
router.use('/', express.static(path.resolve(public + '/index.html')))
或
router.get('/', function(req, res) {
res.sendFile(path.resolve(public + '/index.html'))
})
【问题讨论】:
-
您在问,
use和get之间的区别。router.use服务于所有 4 个 http 动词,get,postbla bla。router.get仅在动词为get时才提供服务 -
router.get('/', express.static(path.resolve(public + '/index.html')))不起作用。所以 router.get...sendFile.. 是更合适的方法吗?因为它只使用 get 动词? -
@StephenWright 这个问题专门针对
sendFile与express.static,而不是use与get。
标签: javascript node.js express