Sudden NPM installation failures on my virtual private server

I’m having trouble with NPM on my VPS. It was working fine until about 20 minutes ago. Now I can’t install anything.

I’m trying to set up a website using nginx and Node.js. When I run this command in my project folder:

npm install express mysql2 dotenv cors

It shows the loading icon for ages (like 5-6 minutes) and then throws an error:

npm error code EAI_AGAIN
npm error syscall getaddrinfo
npm error errno EAI_AGAIN
npm error request to https://registry.npmjs.org/cors failed

I tried changing my DNS to Google’s but no luck. Some people online suggested changing my internet connection, but that’s not really an option for me.

My VPS is hosted on DigitalOcean. I’m not using Docker or Firebase Cloud Functions.

Any ideas on what could be causing this? It’s really frustrating!

This issue sounds like a DNS resolution problem on your VPS. Even though you’ve changed your DNS settings, the changes might not have propagated fully yet. Here’s what I’d suggest:

First, try flushing your DNS cache with ‘sudo systemd-resolve --flush-caches’ if you’re on a systemd-based system. If that doesn’t work, temporarily add Google’s DNS servers to your ‘/etc/resolv.conf’ file.

If the problem persists, it could be a temporary network issue with DigitalOcean or npm’s registry. In that case, you might want to wait a bit and try again later. Alternatively, you could try using a different npm registry temporarily, like Yarn’s registry:

npm config set registry https://registry.yarnpkg.com

Remember to switch back to the official registry once the issue is resolved. If nothing works, it might be worth reaching out to DigitalOcean support to check if there are any known network issues.

yo, had this prob before. try runnin ‘npm config set registry http://registry.npmjs.org/’ in ur terminal. sometimes the https one acts up. if that dont work, maybe ur ISP’s blockin npm? try a VPN or somethin. good luck man!

I’ve encountered similar issues before, and it’s usually related to network connectivity or DNS problems. One thing that worked for me was clearing the npm cache. Try running ‘npm cache clean --force’ and then attempt your installation again.

If that doesn’t solve it, you might want to check if npm can reach the registry. Run ‘npm ping’ to see if you get a response. If not, there could be firewall rules or network restrictions on your VPS blocking npm’s access.

Another troubleshooting step is to temporarily disable your firewall (if you have one) to see if that’s the culprit. Just remember to re-enable it afterward for security.

Lastly, if you’re still stuck, you could try using a package-lock.json file. Sometimes, this helps bypass connection issues by using cached versions of packages. Generate one with ‘npm install --package-lock-only’ and then run your install command again.

Hope this helps! Let us know if you manage to resolve it.