Node.js 在nodejs中使用不同的主机生成API
我是nodejs新手,目前正在使用Node.js 在nodejs中使用不同的主机生成API,node.js,api,Node.js,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 routes/api/index.js- const router = express.Router(); router.g
localhost
运行模拟api
index.js-
const express = require("express");
const api = require("./routes/api");
const app = express();
// Routes
app.use("/api", api); // route api
routes/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-
e、 g.https://example.com/api/v1/users
我如何才能做到这一点?使用Heroku cloud,阅读相关教程。(搜索如何在heroku上部署nodejs服务器。)使用heroku云,阅读相关教程。(搜索如何在heroku上部署nodejs服务器。)