node.js - Express API enpoint localhost:3000/xxx 不起作用,但 localhost:3000/ 是
问题描述
我想用express编写一个 API ,但我一开始就被卡住了。当我访问它时localhost:3000
,它接缝可以工作,但是一旦我写localhost:3000/hello
了一个 404 错误,就会发生(Cannot GET /hello)。
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.json({ message: "Welcome to application." });
});
app.get("/hello", (req, res) => {
res.json({ message: "Welcome to hello." });
});
app.listen(3000, () => {
console.log("Server is running on port 3000.");
});
解决方案
推荐阅读
- r - rollapply 如何“忽略”某些观察结果并使用可变宽度
- javascript - 让 Vue 解释以编程方式插入的组件
- c++ - 将 C++ 容器与 C 语言结构混合
- javascript - Redux 不更新组件
- sql - 未引用 SQL 返回行
- python-3.x - 乐透号码生成器
- flutter - 如何在颤振中实现自定义下拉菜单项?
- python - 使用 np.linalg.eigvals 时,我系统地得到第一个负值的特征值。为什么是这样?
- r - 在 R 中的单个图中使用 ggplot2 为 238 名受试者绘制重复测量的多个箱线图
- aws-pinpoint - 您如何精确地将广告系列发送到自定义渠道?