how to build a router API in server #1033
Answered
by
Mucyo-chris
Sengwamana
asked this question in
Q&A
-
|
how to build a router API in server |
Beta Was this translation helpful? Give feedback.
Answered by
Mucyo-chris
Mar 16, 2026
Replies: 1 comment
-
Then open: Your Node server connects to the API and returns the data.
const app = express(); app.get("/posts", async (req, res) => { app.listen(3000); ✅ Flow: Client → server.js → External API → server.js → Client |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Sengwamana
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node server.js
Then open:
http://localhost:3000/users
Your Node server connects to the API and returns the data.
const express = require("express");
const app = express();
app.get("/posts", async (req, res) => {
const response = await fetch("https://jsonplaceholder.typicode.com/posts");
const data = await response.json();
res.json(data);
});
app.listen(3000);
✅ Flow:
Client → server.js → External API → server.js → Client