Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created February 2, 2021 13:14
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 toddlers/c89958d9a3db93a75c42c9a6a678dfc2 to your computer and use it in GitHub Desktop.
Save toddlers/c89958d9a3db93a75c42c9a6a678dfc2 to your computer and use it in GitHub Desktop.
nodejs http post
//https://blog.bearer.sh/node-http-request/
//https://nodejs.org/en/knowledge/HTTP/clients/how-to-create-a-HTTP-request/
const http = require("http")
let body = JSON.stringify({
title: "Make a request with Node's http module"
})
let options = {
hostname: "postman-echo.com",
path: "/post",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(body)
}
}
http
.request(options, res => {
let data = ""
res.on("data", d => {
data += d
})
res.on("end", () => {
console.log(data)
})
})
.on("error", console.error)
.end(body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment