-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (29 loc) · 826 Bytes
/
server.js
File metadata and controls
35 lines (29 loc) · 826 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
// Auto generate code
const express = require('express');
const app = express();
const PORT = 5000;
const HOST = '0.0.0.0';
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.get('/', (req, res) => {
res.json({
message: 'Hello from Node.js!',
server: 'Node.js/Express',
port: PORT,
host: HOST,
timestamp: new Date().toISOString()
});
});
app.get('/health', (req, res) => {
res.status(200).json({ status: 'OK', uptime: process.uptime() });
});
app.post('/echo', (req, res) => {
res.json({ received: req.body, method: 'POST' });
});
// Start server
app.listen(PORT, HOST, () => {
console.log(`🚀 Node.js server running on http://${HOST}:${PORT}`);
console.log(`📍 Local: http://localhost:${PORT}`);
});