I am trying to get data from a udemy API. I can get it with cURL in the console but not with fetch
. Please can anyone look at my code and let me know what I am doing wrong?
const fetch = require("node-fetch");
const express = require("express");
const app = express();
const port = process.env.PORT || 3000;
const path = require("path");
app.use(express.static("public"));
app.use(express.static(path.resolve(__dirname, "public")));
app.get("/", (req, res) => {
res.sendFile("index.html", { root: __dirname });
});
app.get("/contact", (req, res) => {
res.sendFile("contact.html", { root: __dirname });
});
const client_id = "client_id";
const client_secret = "client_secret";
const client = Buffer.from(`${client_id}:${client_secret}`).toString("base64");
fetch("https://www.udemy.com/api-2.0/courses/", {
headers: {
Authorization: `Basic ${client}`,
},
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch((err) => {
console.log(err);
});