首页 > 解决方案 > Learning Node & Express - 在 Post route not found 错误中难倒

问题描述

总的来说,我对 API 和 Web 开发领域非常陌生。我目前正在尝试将数据发布到我的代码中的假数据。

当我使用邮递员获取数据时,它可以工作。当我尝试发布数据时,出现 404 错误。

任何建议都会很棒..再一次,我对这一切都很陌生,所以请对这个婴儿编码器温柔一点。

const app = express();
const { v4: uuidv4 } = require("uuid");

const PORT = 3000;

//middleware
app.use(express.json());

let bountyHunter = [
  {
    firstName: "Dirty",
    lastName: "Bubble",
    living: true,
    bountyAmount: 4000,
    type: "Bubble",
    _id: uuidv4(),
  },
  {
    firstName: "Man",
    lastName: "Ray",
    living: true,
    bountyAmount: 1000,
    type: "Humanoid",
    _id: uuidv4(),
  },
  {
    firstName: "Sinister",
    lastName: "Slug",
    living: true,
    bountyAmount: 500,
    type: "Slug",
    _id: uuidv4(),
  },
];

//GET Route
app.get("/bountyHunter", (req, res) => {
  res.send(bountyHunter);
});

//POST Route
app.post("/bountyHunter", (req, res) => {
res.send(`Successfully added to the database`);
});

// server startup logic
app.listen(PORT, () => {
  console.log(`App started on port: ${PORT}`);
});```

标签: node.jsapiexpresspostman

解决方案


推荐阅读