npm link — use a local package without publishing

# 1. In the package you are developing:
cd /path/to/my-library
npm link

# 2. In the project that uses it:
cd /path/to/my-app
npm link my-library

# Now changes in my-library are immediately reflected in my-app

You are developing a library and want to test it in a real project without publishing to npm.

How npm link works

npm link creates a symlink from the global node_modules to your local package. npm link my-library then symlinks from the project's node_modules to the global one.

# Step 1 creates:
~/.nvm/versions/node/v20.x.x/lib/node_modules/my-library -> /path/to/my-library

# Step 2 creates:
/path/to/my-app/node_modules/my-library -> ~/.nvm/.../node_modules/my-library

Unlink when done

# In the consumer project
npm unlink my-library

# Re-install the published version
npm install my-library

Alternative: file: protocol in package.json

// package.json
{
  "dependencies": {
    "my-library": "file:../my-library"
  }
}
npm install