node.js - how to get the path of an installed npm package via npm CLI/API? -


this question has answer here:

i'm writing npm script, packed npm package, exposing main executable node_modules/.bin hosting project.

this script has own npm dependencies, , script flow relies on copying 1 of these dependencies different location, needs know dependency installed.

how can find (via api or npm cli) dependency installed inside host's node_modules?

see a more elaborated answer here. answer kept reference.


you can use npm ls --parseable flag, will:

show parseable output instead of tree view.

for example:

$ npm ls my-dep -p /users/my-user/dev/host-project/node_modules/my-dep 

you should aware command can output irrelevant errors stdout (e.g. extraneous installations) — work around this, activate --silent flag (see loglevel in docs):

$ npm ls my-dep -ps 

in npm script, command can integrated using child process, in case it's preferred run command without --silent flag allow capturing error.

if error catched, can decide whether fatal or not (e.g. aforementioned error extraneous package should ignored).


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -