如何服务特定的文件节点服务器
让我们说我有一个带有2个文件的目录:c:\ file1 \ index.html和c:\ file1 \ test.html。我正在尝试在特定端口上使用节点JS启动服务器。现在,我使用app.use('/',express.static(path.join(__ dirname)))
作为服务文件的目录。我的问题是,如何使用我拥有的代码来使其服务c:\\ file1 \ test.html
,它可以使用c:\\ file1 \ index.html
?提前致谢。
const express = require('express')
const app = express()
const path = require('path')
//loads index.html
app.use('/', express.static(path.join(__dirname)))
app.listen(3000, () => console.log('Server up on port 3000'))
Let us say I have a directory with 2 files: c:\file1\index.html and c:\file1\test.html. I am trying to start a server with node js on a specific port. Now I used app.use('/', express.static(path.join(__dirname)))
as the directory to serve the file. My question is how can I make it serve c:\\file1\test.html
with the code I have right now it serves c:\\file1\index.html
? Thanks in advance.
const express = require('express')
const app = express()
const path = require('path')
//loads index.html
app.use('/', express.static(path.join(__dirname)))
app.listen(3000, () => console.log('Server up on port 3000'))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个适合您吗?
Would this work for you?