npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Cannot use npm view command programmatically

I need to use the npm view command programmatically to get a list of all available versions for a given package. Basically, I use it like this:

npm.load(() => {
  npm.commands.view([pkg, 'versions'], true, (err, data) => {

Everything worked fine until npm 6.6.0. I read at the source code, and it looks like in case silent parameter is true (second parameter of npm.commands.view in the code below), nothing is returned (and if silent is false`, available versions are printed to stdout, and the result is returned). You can see it here:

My question is: why, if silent is true, nothing is returned? I would expect that nothing is printed to stdout, but the result should be returned, right?

If that’s a bug, I would be happy to submit a pull request. If that’s the expected behaviour, can you give me more explanation to understand?

PS: that is my first message on this support forum, I’m sorry if I made a mistake while posting this issue.