forked from AliceNN-ucdenver/CSC3916_Assignment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (25 loc) · 751 Bytes
/
app.js
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
var server = require("http").createServer();
server.on("request", (request, response) => {
var body = [];
request.on("data", chunk => {
body.push(chunk);
});
request
.on("end", () => {
let bodyString = body.concat().toString();
console.log(bodyString);
response.end(bodyString);
})
.on("error", () => {
response.statusCode = 400;
response.end();
});
response.on("error", err => {
console.error(err);
});
});
server.listen(process.env.PORT || 8008, () => {
console.log("Server listening at 8008");
});
module.exports = server; // for testing
//curl -d "echo" -H "Content-Type: text" -X POST http://localhost:8008