【问题标题】:POST request to server gives {} as output in terminal对服务器的 POST 请求将 {} 作为终端的输出
【发布时间】:2020-01-16 16:17:58
【问题描述】:

我尝试连接到数据库,但它一直以 {} 形式提供数据,尽管它已成功连接,并且有人告诉我这个文件中有错误,如果我想查看它从数据库传递的身体参数那么我需要更正这个文件,那我该怎么办

const connection = require("./model");
const express = require("express");
const app = express();
const path = require("path");
const expressHandlebars = require("express-handlebars");
const bodyparser = require("body-parser");
const todolist = require("./routes/todo");

app.use(bodyparser.json());

app.set('views', path.join(__dirname, "/views"));
app.engine("hbs", expressHandlebars({
    extname: "hbs",
    defaultLayout : "mainlayout",
    layoutsDir : __dirname + "/views/layouts"
}));

app.use("/todo" , todolist );

app.set("view engine", "hbs")
app.get("/", (req,res) =>{
    //res.send("Hello World")
    res.render("index",{})
})

app.listen("2000", () =>{
    console.log("Server Started");
});

【问题讨论】:

  • 这个文件中的 POST 端点在哪里?您使用的 POST api 是什么?
  • 请求您对这个问题进行一些澄清。

标签: node.js mongodb express mongoose


【解决方案1】:

尝试做这样的事情:

app.get("/", (req,res) =>{
//res.send("Hello World")
 res.render("index",{
  title:'index page' 
 })
})

//connection 
const PORT = process.env.PORT || 3000
app.listen(PORT, console.log(`listening on port 
${PORT}`));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多