So I need to create a endpoint i.e. A GET request in NodeJS which will make a curl call to another api and return a data. I am using native method of NodeJS to make curl call using https module. But I am not getting any response when I hit my nodeJS api (i.e. /api/mailers/campaigns). If I try to print curl response in console it returns me correct data. Is there anything I am missing?
Basically for security purpose I will hit my nodejs endpoint from my frontend
const app = express();
const http = require("https");
app.get('/api/mailers/campaigns', (req, res) => {
var chunks = [];
var options = {
"method": "GET",
"hostname": "api.mailerlite.com",
"port": null,
"path": "/api/v2/campaigns",
"headers": {
"x-mailerlite-apikey": "api_key",
"content-type":"application/json"
}
};
var req = http.request(options, function (res) {
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
return body.toString();
});
});
req.end();
})