节点运行时出现“Cannot GET /”错误"/>
使用节点运行时出现“Cannot GET /”错误
当我尝试在超级终端中使用 nodemon 运行我的 app.js 时,它显示错误 cannot GET /
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const homeStartingContent = "Lacus vel facilisis"
const aboutContent = "Hac habitasse platea"
const contactContent = "Scelerisque eleifend"
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.get("/", function(req, res){
res.render("home",{startingContent:homeStartingContent});
});
app.get("/about",function(req, res){
res.render("about",{about:aboutContent});
});
app.get("/contact",function(req, res){
res.render("contact", {contact:contactContent});
});
app.get("/compose", function(req, res){
res.render("compose");
});
app.post("/compose", function(req, res){
console.log(req.body.postTitle);
});
app.listen(3000, function() {
console.log("Server started on port 3000");
});
当我使用 VSCode 终端运行时它会正常工作。我不知道这有什么问题。请帮助!!!
回答如下:更多推荐
使用节点运行时出现“Cannot GET /”错误
发布评论