[英]how can I send a file that's inside another folder using express.js?
why is my browser says that the folder and the folder I wanted to send are don't exist?为什么我的浏览器提示我要发送的文件夹和文件夹不存在?
const express = require('express');
const app = express();
const port = 3000 || process.env.PORT;
app.get('/', (req, res) => {
res.sendFile(__dirname + '/Structures/index.html');
})
app.listen(port, () => {
console.log('listening on port' + port);
});
check the path of index.html com your foldering should be like this:检查 index.html com 的路径,你的文件夹应该是这样的:
if your foldering like this:如果你的文件夹是这样的:
user path
module and join
path so just try用户
path
模块和join
路径,所以试试
const path = require('path');
const express = require('express');
const app = express();
const port = 3000 || process.env.PORT;
app.get('/', (req, res) => {
// res.sendFile(__dirname + '../Structures/index.html');
res.sendFile(path.join(__dirname,'../Structures/index.html'))
})
app.listen(port, () => {
console.log('listening on port' + port);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.