LoginSignup
2
2

More than 5 years have passed since last update.

`Npm link` for real-time development of node dependencies

Last updated at Posted at 2014-06-21

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.

atom-spotify in action

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):

Before:
Screen Shot 2014-06-20 at 10.39.55 PM.png

After:
Screen Shot 2014-06-20 at 10.40.59 PM.png

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.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2