npm link: detecting links

2021-09-23

 | 

~1 min read

 | 

156 words

After you’re all done linking packages together for local development, it can be hard to know whether or not the connection has been successfully severed.

To check, we can use the npm ls command:

% npm ls --depth=0 --link=true

If a package is linked, you’ll see something like:

my-app@0.37.0 /Users/stephen.weiss/code/my-app
└── my-linked-library@0.2.5 -> /Users/stephen.weiss/code/libs/my-linked-library
...

In this case, my app, my-app has a linked library, my-linked-library which is symlinked from a sibling directory libs.

If there are no linked packages, you’ll see:

my-app@0.37.0 /Users/stephen.weiss/code/my-app
└── (empty)

Note, while editors are starting to help indicate if a package is linked (e.g., VS Code has a small arrow indicator on packages in node_modules), I prefer using the command line to know more definitively. I also just find it much simpler than navigating through a UI to detect whether or not there’s a small visual indicator, particularly when the Explorer can often lag.


Related Posts
  • 2021 Daily Journal


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!