Guest User

Untitled

a guest
Sep 20th, 2019
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const http = require('http');
  2.  
  3. var options = {
  4. host: "jsonplaceholder.typicode.com",
  5. path: "/posts",
  6. method: "POST",
  7. }
  8.  
  9. var req = http.request(options, function (res) {
  10. var responseString = "";
  11.  
  12. res.on("data", function (data) {
  13. responseString += data;
  14. // save all the data from response
  15. });
  16. res.on("end", function () {
  17. console.log(responseString);
  18. // print to console when response ends
  19. });
  20. });
  21.  
  22. req.on('error', (err) => {
  23. console.log('error:', err);
  24. })
  25.  
  26. req.end();
RAW Paste Data