-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-server.js
More file actions
40 lines (35 loc) · 987 Bytes
/
Copy pathsimple-server.js
File metadata and controls
40 lines (35 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const app = express();
const port = process.env.PORT || 3001;
app.use(express.json());
// Health check endpoint
app.get('/api/health', (req, res) => {
res.json({
status: 'OK',
timestamp: new Date().toISOString(),
server: 'Node.js Express Server'
});
});
// Example API endpoint
app.get('/api/custom', (req, res) => {
res.json({
message: 'This is a custom API route from Express server',
data: {
version: '1.0.0',
environment: process.env.NODE_ENV || 'development'
}
});
});
app.use((req, res) => {
res.status(404).json({
error: 'Route not found',
message: 'This route is not handled by the Express server',
path: req.path,
method: req.method
});
});
app.listen(port, () => {
console.log(`Express server running on http://localhost:${port}`);
console.log(`Health check: http://localhost:${port}/api/health`);
console.log(`Custom API: http://localhost:${port}/api/custom`);
});