Angular itself does not create APIs, but it can consume APIs. However, if you want to build a backend API for an Angular app, you can use Node.js with Express.js.
1. Set Up Node.js and Express
Install Node.js if not already installed.
Create a new folder and initialize a project:
mkdir my-api && cd my-api
npm init -y
npm install express cors body-parser mongoose
2. Create server.js (Main API File)
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.get("/api/message", (req, res) => {
res.json({ message: "Hello from API!" });
});
const PORT = 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
3. Run the API Server
node server.js