Skip to content

Instantly share code, notes, and snippets.

@yaasita
Created April 28, 2020 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/99311e1dd298e61170373bcbaf6b053e to your computer and use it in GitHub Desktop.
Save yaasita/99311e1dd298e61170373bcbaf6b053e to your computer and use it in GitHub Desktop.
const express = require("express");
const app = express();
const port = 3000;
const concat = require("concat-stream");
app.use(function (req, res, next) {
req.pipe(
concat(function (data) {
req.body = data;
next();
})
);
});
const fs = require('fs');
app.post("/api", (req, res) => {
console.log(req.method);
console.log(req.body.toString());
console.log(req.headers);
fs.writeFileSync("/tmp/rawdata", req.body);
res.send("Hello!");
});
app.listen(port, () =>
console.log(`Example app listening at http://localhost:${port}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment