Published at
Updated at
Reading time

This post is part of my Today I learned series in which I share all my learnings regarding web development.

Today, I was reading the article Making it Easier to Work With Local npm Packages written by Aaron Parrel. He describes that you can specify local packages and modules right in your package.json.

  "dependencies": {
    "durable-functions": "file:../azure-functions-durable-js",

This package.json example includes a durable-functions package. It is not installed from npm, though. durable-functions is a local package which the file: prefix already unveils.

When can this be useful?

The primary use case for local packages is npm package development. At some point, you want to test your new package inside another module/package/site. This moment is when you need a way to reference this local package from within another project.

As Aaron points out, one way to make that work is to use npm link. Unfortunately, my experience with npm link is only "so-so". I guess it's the same as using ln -s to create a symlink – you never get it right the first try!

Local package paths feel more intuitive to me. After reading more about them, I discovered that the npm install command supports them, too. 😲

npm install ../some-local-package

This install command will add some-local-package to your package.json's dependencies. The local package path will then include a file: prefix. It'll also create a symlink in your node_modules directory pointing to the local package. Pretty sweet!

If you want to install a local package, the defined package path has to include a valid package.json – otherwise, npm install will fail.

I have to say this behavior is very handy when developing local packages and modules! It removes the need for creating symlinks manually and I always struggle with that!

Related Topics

Related Articles