This is something that many people probably already know, but I'm going to write about it since I haven't seen anything really obvious on the internet.
Npm-link lets you use symbolic links from your package to anywhere else you choose to link to the package. You can run npm link
in your package and then run npm link my-package
in whatever project you want to use it.
That's it! Now for a silly project involving this...
Example Time
Anyone who's seen my other articles probably knows that I like Github's Atom.io way too much for stupid reasons. Good news! There's a plug-in that I love using called atom-spotify
, but I want to add some extra features to it. Let's get started.
Setup
apm
is the Atom Package Manager, which works almost exactly like npm
. First, we will have to have our repository checked out:
$ git clone https://github.com/kimagure/atom-spotify
Once we have that checked out, we need to cd
in and install dependencies like any node project.
$ apm install
Installing modules ✓
Next, link it in apm by running apm link
. You'll see something like this:
$ apm link
/Users/jwoo/.atom/packages/atom-spotify -> /Users/jwoo/github/atom-spotify
Cool. Start up atom
and take a look.
Workflow
As you can see, it works! Now, if you change something in here, your changes will be automatically reflected in the .atom/packages/atom-spotify
directory, so you can use this to make changes that you can see and use right as you make the changes!
E.g. if we change Now Playing
and Paused
to something silly like ぷれいちゅうです〜
and ポーズしていまーす〜
and save and reload (ctrl+opt+cmd+L), we will see that the status bar changes (i.e. with 'Show Play Icon As Text' on):
Conclusion
Ain't that something? You can apply the same thing in your node projects, but with one big difference: npm link
creates the symlink for use in projects but requires you link to the project specifically. npm link
in my-super-project
requires a corresponding npm link my-super-project
in my-other-project-that-depends-on-my-super-project
.
Now you can develop on multiple interdependent projects with no problem! Cool stuff.