Categories
JavaScript Answers

How to make a https post in Node.js without any third party module?

Spread the love

To make a https post in Node.js without any third party module, we use fetch.

For instance, we write

const res = await fetch("https://nodejs.org/api/documentation.json");
if (res.ok) {
  const data = await res.json();
  console.log(data);
}

to call fetch to make a get request to the URL.

We get the JSON response with res.json.

We check if the request works with res.ok.

fetch is built into Node.js since version 18.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *