-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeserver.js
More file actions
30 lines (28 loc) · 919 Bytes
/
nodeserver.js
File metadata and controls
30 lines (28 loc) · 919 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
const http = require('node:http');
http.createServer((request, response) => {
if (request.method !== "POST") {
response.statusCode = 405;
return response.end("Method not allowed");
}
let body = [];
request
.on('data', chunk => {
body.push(chunk);
})
.on('end', () => {
try {
body = Buffer.concat(body).toString();
const parsedBody = JSON.parse(body);
const events = parsedBody.events;
//console.log(events);
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify(events));
} catch (error) {
response.statusCode = 403;
response.end("Cannot find events");
}
});
})
.listen(8000, () => {
console.log(`Server running on http://localhost:8000`);
});