Can't request to https://registry.npmjs.org using nodejs

I want to write a program to show some npm packages, there's example code:

const https = require('node:https')
const url = '
const req = https.request(url, res => { console.log('statusCode:', res.statusCode) console.log('headers:', res.headers) res.on('data', d => { process.stdout.write(d) })
})
req.on('error', e => { console.error(e)
})
req.end()

But get error:

Error: connect ETIMEDOUT 104.16.23.35:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) { errno: -4039, code: 'ETIMEDOUT', syscall: 'connect', address: '104.16.23.35', port: 443
}

At first, I think about it is due to the problem of my own network. But when I input the address in browser, it works just well. It makes me very confused, why it works fun in browser but not good with nodejs?

Node version: 16.15.0
Npm version: 8.5.5
System: windows10
No proxy

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like