1

How do I get a list of all globally installed npm packages using the npm.commands.ls command?

1 Answer 1

1

First, you have to have npm installed locally(npm i npm -S). Second, you need to do npm.load to initialize npm. Finally you can just use npm.commands.ls to get the list. What is important is to add the global: true and depth: 0 parameters into the load function.

var npm = require('npm')

npm.load({
    loaded: false,
    progress: false,
    loglevel: 'error',
    global: true,
    depth: 0
}, () => {
    npm.commands.ls([], true, (err, data) => {
        console.log(Object.keys(data.dependencies))
    })
})

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.