1

I'm developing a npm package along with an application that uses it. I'm making a ton of small changes in this package and would like to be able to rerun the application after every iteration. The package is listed as a dependency in package.json file within the app.

Currently, I've got the dependency pointing to a branch in remote git repository, but I'd like to speed this process up and not have to push every change. Is it possible to list the dependency as a directory in local file system?

Hubert OG
  • 19,314
  • 7
  • 45
  • 73
  • Does this answer your question? [how to specify local modules as npm package dependencies](https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies) – Inigo May 22 '20 at 17:11
  • The answers at the above link are for more complete. None of the answers include the top answer there. – Inigo May 22 '20 at 17:12

3 Answers3

5

Try using npm link in the local directory. Should link your globally installed module to the local copy.

sent1nel
  • 1,580
  • 1
  • 15
  • 31
  • 2
    to clarify, you'll use a combination of `npm link` in your dependency's project folder and then `npm link [dependency]` in your using project's folder, where [dependency] is whatever the project's name is in package.json – MateodelNorte Sep 18 '14 at 17:28
0

As far as I know, you can't using package.json. Assuming your module is in /home/username/my_module, you can do this:

npm install /home/username/my_module
Jonathan Wiepert
  • 1,222
  • 12
  • 12
0

It turns out the easiest way to achieve this is to just link the package directory directly into node_modules.

cd node_modules
ln -is /path/to/package/directory packagename
Hubert OG
  • 19,314
  • 7
  • 45
  • 73
  • 1
    npm link is the correct way to go. SEe @sent1nel's answer. – MateodelNorte Sep 18 '14 at 17:27
  • 1
    I still believe this is the best way as it works, doesn't involve additional tools, what happens is clear and I am certain that changes don't leak to other projects. I don't see a reason for downvote. – Hubert OG Sep 19 '14 at 04:50
  • It may be doing the same thing, but `npm link` is hiding the implementation on purpose. Anyone developing Node.js already has npm, and if the implementation changes `npm link` and `npm unlink` will still work. – MateodelNorte Sep 19 '14 at 15:16
  • Does npm link let you have the same module linked to different local directories in different projects on the same machine? It doesn't look like it, so this certainly may have its advantages. – Armand Sep 30 '15 at 10:01
  • This is NOT the way to go. `node_modules` is supposed to be the reification of the dependencies specified in `package.json`. For example `npm ci` will obliterate such symbolic links and you'll have to do it over. – Inigo May 22 '20 at 16:44