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

How to get the arclen between two curve points in Maya? -

C++ Linked List -

git svn - Unignore directories in git-svn (adding directories to a sparse checkout) -