Skip to content

Commit 3e691cb

Browse files
feat(api): initialize Express server with health check and hello endpoint
- Set up Express server with CORS and JSON parsing middleware - Implemented root endpoint to confirm API is running - Added health check endpoint returning status and timestamp - Created hello endpoint returning a greeting message - Configured TypeScript with strict settings and module resolution
1 parent 5132765 commit 3e691cb

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

api/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
"name": "api",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "dist/index.js",
66
"scripts": {
7+
"dev": "nodemon --watch src --exec \"ts-node\" src/index.ts",
8+
"build": "tsc -p tsconfig.json",
9+
"start": "node dist/index.js",
710
"test": "echo \"Error: no test specified\" && exit 1"
811
},
912
"keywords": [],
@@ -16,6 +19,7 @@
1619
"express": "^5.1.0"
1720
},
1821
"devDependencies": {
22+
"@types/cors": "^2.8.19",
1923
"@types/express": "^5.0.5",
2024
"@types/node": "^20.19.24",
2125
"nodemon": "^3.1.10",

api/src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import express from "express";
2+
import cors from "cors";
3+
4+
const app = express();
5+
app.use(cors());
6+
app.use(express.json());
7+
8+
const PORT = process.env.PORT || 4000;
9+
10+
app.get("/", (_req, res) => {
11+
res.send("API is running");
12+
});
13+
14+
app.get("/api/health", (_req, res) => {
15+
res.json({ status: "ok", timestamp: Date.now() });
16+
});
17+
18+
app.get("/api/hello", (_req, res) => {
19+
res.json({ message: "Hello from the API" });
20+
});
21+
22+
app.listen(Number(PORT), () => {
23+
// eslint-disable-next-line no-console
24+
console.log(`API server listening on port ${PORT}`);
25+
});

api/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "CommonJS",
5+
"outDir": "dist",
6+
"rootDir": "src",
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"skipLibCheck": true
11+
},
12+
"include": ["src/**/*.ts"]
13+
}

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)