Q:

What does "npm set registry https://registry.npmjs.org/" do?

I had problem installing cordova using npm.
From the answer found here, the trick is to run npm set registry https://registry.npmjs.org/
What exactly does this command do and why does it solve the problem of installing cordova?
Stuck when installing cordova

A:

As you can read here, the npm Registry is a public collection of packages of open-source code for Node.js, front-end web apps and the JavaScript community at large.
In a standard install of npm, the registry is set to https://registry.npmjs.org/. That is to say, this is the address that npm will download packages from when you run npm install <anything>.
You can however change this value with the command npm set registry <new url>. That means that any future npm install commands will fetch packages from <new url> instead. You might want to do this if your company runs its own private mirror of the registry, or if you want to use a different mirror in the case that https://registry.npmjs.org/ is down, or too slow. This SO answer lists a couple of alternative mirrors.

the trick is to run npm set registry https://registry.npmjs.org/ What exactly does this command do and why does it solve the problem of installing cordova?

This command resets the registry value to its default and causes npm to download packages from https://registry.npmjs.org/. Why this solved your particular problem is hard to say, as https://registry.npmjs.org/ is the default value for a new install of npm. It seems something changed this value on your computer, but without further information it is difficult to say what.
In future, you can also check what this value is set to using npm get registry.

