使用节点运行时出现“Cannot GET /”错误

问题描述 投票:0回答:0

当我尝试在超级终端中使用 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 终端运行时它会正常工作。我不知道这有什么问题。请帮助!!!

node.js localhost ejs nodemon
© www.soinside.com 2019 - 2024. All rights reserved.