I have a simple express app with "index.js package.json" in a folder.
I have installed all the required libraries.
I am not getting why the below code does not work with the Github API URL but works for the jsonplaceholder.typicode.com URL. Can someone help with this ?
index.js
const express = require('express');
const cors = require('cors');
const axios = require('axios');
axios.defaults.withCredentials = true;
const app = express();
app.use(cors());
app.get('/api', (req, res) => {
// const url = https://jsonplaceholder.typicode.com/todos
;
const url = https://api.github.com/users/memahesh
;
axios.get(url, { headers: { 'Access-Control-Allow-Origin': '*' } }).then(response => {
res.json({data: response.data});
});
});
const PORT = 5000;
app.listen(PORT, () => console.log(Listening on port ${PORT}
));
Console Log:
(node:1912) UnhandledPromiseRejectionWarning: Error: connect ETIMEDOUT 13.233.76.15:443
[0] at TCPConnectWrap.afterConnect as oncomplete
Thanks in advance,
Top comments (4)
You might want to pass in options to axios like this
If not could you please post your error message?
I have updated the post. There seems to be a ETIMEDOUT error. But, I know the Github API is working fine.
I am working behind a proxy. Is that an issue ?
Have you tried using
axios-proxy-fix
? It is a npm package.No, I will try that.