【发布时间】:2021-11-27 16:40:17
【问题描述】:
目前我在同一个文件夹中使用 html 文件。那么如何使用 express 获取保存在不同文件夹中的 html 文件。谢谢。
const express=require('express')
const path=require('path')
const app=express()
app.get('/',function(req,res){
res.sendFile(path.join(__dirname,'index.html'))
})
app.get('/about',function(req,res){
res.send('about')
})
app.listen(3000,function(){
console.log('Server Online')
})
【问题讨论】:
-
console.log(__dirname);看看。例如,您可以使用path.join(__dirname, "html/index.html");。
标签: javascript node.js express web-development-server