Quickly open node package in your $EDITOR

Sometimes I need to open a package under node_modules and it’s not very convenient yet, I’d have to remember to type in subl node_modules/<name>.

With Ruby’s Bundler, it’s a simple bundle open gem_name and the gem will be opened in the default $EDITOR. However, for node, it’s not quite as nice. A simple solution is to add a new “open” script to package.json as follow:

"open": "run(){ $EDITOR node_modules/$1; }; run"

So now you can do yarn open package_name and voila, you will have the package open up nicely in your favorite editor! Neat.

Leave a Reply