Skip to content

Instantly share code, notes, and snippets.

@bultas
Last active January 11, 2019 18:09
Show Gist options
  • Save bultas/c17997cadf77be7458d4dc69d44f60b7 to your computer and use it in GitHub Desktop.
Save bultas/c17997cadf77be7458d4dc69d44f60b7 to your computer and use it in GitHub Desktop.
Node handle basic HTTP request - read POST and return JSON
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