How to set up a local npm package from downloaded source code?

I’ve got a module’s source code downloaded on my machine, and I need to install it as a dependency in my current project. I don’t want to install it globally on my system; I just want it available for the specific project I’m working on.

I’m looking for the simplest approach to get this working. Should I be using a specific npm command, or is there a particular file structure I need to follow? I’ve tried a few different methods, but nothing seems to work properly.

Any guidance on the best practice for this would be really helpful. Thanks!

I just run npm install with the relative path to the downloaded module. If your source folder is my-module and it’s in the same directory as your project, go to your project directory and run npm install ../my-module. This installs it as a local dependency instead of global, so it’s only available for your current project. Just make sure the source directory has a valid package.json or npm won’t recognize it. Works great for local development.

you can also copy the source straight into node_modules. Just create a folder with the package name in your project’s node_modules dir and drop all the source files there. it’s messy, but works when npm install and linking fail. Don’t forget to add it to .gitignore so u dont accidentally commit it.

Use npm link for this. Go to your downloaded module directory and run npm link - this creates a symbolic link in your global node_modules. Then head back to your project directory and run npm link module-name (use whatever’s in the module’s package.json name field). This is great for development since any changes you make to the source code show up immediately in your project - no reinstalling needed. The module doesn’t actually get installed globally for other projects, it just uses the linking mechanism. Just make sure the downloaded source has a proper package.json structure before you link it.