首页 > 解决方案 > 在 nodejs 中使用不同的主机制作 API

问题描述

我是 nodejs 的新手,目前localhost用于运行模拟 API。

index.js -

const express = require("express");
const api = require("./routes/api");
const app = express();

// Routes
app.use("/api", api); // route api

路线/api/index.js -

const router = express.Router();

router.get("/path-to-certain-resource", async (req, res) => {
 });
//...
router.post("/path-to-another-resource", async(req,res) => {
});

我需要使用预定义的 url 创建一个新的 API - 例如https://example.com/api/v1/users

我怎样才能做到这一点?

标签: node.jsapi

解决方案


推荐阅读