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

编程入门 行业动态 更新时间:2024-10-04 13:26:51

使用<a href=https://www.elefans.com/category/jswz/34/1771452.html style=节点运行时出现“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 /”错误

本文发布于:2024-05-31 03:31:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!