request end request write node js

Solutions on MaxInterview for request end request write node js by the best coders in the world

showing results for - "request end request write node js"
Ava
10 Aug 2017
1const http = require("http")
2
3let body = JSON.stringify({
4  title: "Make a request with Node's http module"
5})
6
7let options = {
8  hostname: "postman-echo.com",
9  path: "/post",
10  method: "POST",
11  headers: {
12    "Content-Type": "application/json",
13    "Content-Length": Buffer.byteLength(body)
14  }
15}
16
17http
18  .request(options, res => {
19    let data = ""
20    res.on("data", d => {
21      data += d
22    })
23    res.on("end", () => {
24      console.log(data)
25    })
26  })
27  .on("error", console.error)
28  .end(body)
29