-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
27 lines (25 loc) · 781 Bytes
/
utils.js
File metadata and controls
27 lines (25 loc) · 781 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
//utils.js
// Controls a standard Web API use case
// It includes the getReqData() function
// which retrieves data from the client on the server
function getReqData(req) {
return new Promise((resolve, reject) => {
try {
let body = "";
// listen to data sent by client
req.on("data", (chunk) => {
// append the string version to the body
body += chunk.toString();
});
// listen till the end
req.on("end", () => {
// send back the data
resolve(body);
});
} catch (error) {
reject(error);
}
});
}
// since only one function don't need to export entire file
module.exports = { getReqData };