Black lives matter
Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Cover of book “Tackling TypeScript”
Book (first part free online)
Logo of newsletter “ news”
Newsletter (free)

Tip: npm-installing directories

[2018-04-24] dev, javascript, nodejs, npm
(Ad, please don’t block)

Quick tip: npm lets you install directories, which is occasionally useful for organizing projects. For example, as a temporary step before uploading packages to npm (think lightweight npm link).

An example project  

As an example, let’s assume, we are writing a suite of Node.js-based CLI tools:


Each of tool1, tool2 and helpers is an npm package with its own package.json and node_modules/.

npm-installing the directory helpers/  

npm lets you do:

$ cd tool1/
$ npm install ../helpers

Then npm does the following:

  • It installs the dependencies of helpers.
  • It adds a symlink to ../../helpers/ in tool1/node_modules.
  • It adds an entry to the dependencies:
    "dependencies": {
      "helpers": "file:../helpers",

Et voilà! Now tool1’s “sibling dependency” on helpers will be (re)created whenever you do an npm install for tool1.