0

I have an express server on localhost from which I am making an Api call

function get(){
    console.log('calling get')

    fetch('https://www.nseindia.com/api/marketStatus')
    .then(val=>{console.log(val)})
    .catch(err => console.log(err))

}

app.listen(3000, () => {
    console.log('Listening on Port 3000');
    get()
});

the output which I get with using node-fetch is the following and It doesn't throw any kind of an error. It doesn't go inside then or the catch callback.

Listening on Port 3000
calling get

but with axios the code inside the then callback runs fine

function get(){
    console.log('calling get')

    axios.get('https://www.nseindia.com/api/marketStatus').then(val=>{
         console.log(val)
     }).catch(error => {
         console.log(error)
     })

}

app.listen(3000, () => {
    console.log('Listening on Port 3000');
    get()
});

any Help would be greatly appreciated.

2
  • seems odd. maybe instead of console.log(val) try console.log('test') Commented Dec 24, 2021 at 19:25
  • no, still not printing test. Commented Dec 24, 2021 at 19:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.