Created
August 2, 2019 07:32
-
-
Save baflo/2dcb110b3798e5d5c146f1cb7bf0965c to your computer and use it in GitHub Desktop.
quick node server
This file contains 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
http.createServer(function(r, s) { | |
var body = []; | |
r.on("data", function(chunk) { | |
body.push(chunk) | |
}); | |
r.on("end", function() { | |
body = Buffer.concat(body).toString(); | |
body = r.headers["content-type"] === "application/json" ? JSON.parse(body) : body; | |
console.log(r.method, r.url, r.headers, JSON.stringify(body, null, 2)); | |
s.write("OK"); | |
s.end(); | |
}); | |
}).listen(1330); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment