Last active
January 11, 2019 18:09
-
-
Save bultas/c17997cadf77be7458d4dc69d44f60b7 to your computer and use it in GitHub Desktop.
Node handle basic HTTP request - read POST and return JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const handle = (req, res) => { | |
let data = ""; | |
req.on("data", chunk => { | |
data += chunk; | |
}); | |
req.on("end", () => { | |
const { token } = JSON.parse(data); | |
res.setHeader("Content-Type", "application/json"); | |
res.end(JSON.stringify({ token })); | |
}); | |
}; | |
http | |
.createServer(handle) | |
.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment