我正在开发一个博客来学习节点和javascript,但我遇到了问题。我无法获取我的页面,也不知道为什么。有人可以带领我或给我解释这个问题的方法吗,谢谢。
我在下面放了index.js和package.json。如您所见,我已经安装了nodemon和bootstrap,并且正在cmd中完成所有这些操作。
index.js
const path = require('path');
const expressEdge = require('express-edge');
const express = require('express');
const app = new express();
app.use(express.static('public'));
app.use(expressEdge);
app.set('views', __dirname + '/views');
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, './pages/index.html'));
});
app.get('/about', (req, res) => {
res.sendFile(path.resolve(__dirname, './pages/about.html'));
});
app.get('/contact', (req, res) => {
res.sendFile(path.resolve(__dirname, 'pages/contact.html'));
});
app.get('/post', (req, res) => {
res.sendFile(path.resolve(__dirname, 'pages/post.html'));
});
app.listen(3000, () => {
console.log('App listening on port 3000')
});
package.json
{
"name": "projet3web",
"version": "1.0.0",
"description": "Create a blog",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"},
"keywords": [
"blog"],
"author": "Kym lusinchi Vincent Blanc El Hachemi Sabi",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.3.1",
"bootstrap-datepicker": "^1.8.0",
"express": "^4.16.4",
"express-edge": "^1.0.0",
"nodemon": "^1.18.11",
"popper.js": "^1.15.0",
"startbootstrap-clean-blog": "file:startbootstrap-clean-blog",
"tooltip.js": "^1.3.1"
}
}
最佳答案
检查您在重新发送中的路线是否正确。我认为您不需要.html
我不知道您的文件树是什么样子,但是如果它是标准文件,则不需要在路径的开头加点
无论如何,我认为你应该使用res.render('/');