How To Install A Local Module Using NPM?
Last Updated :
07 Jan, 2025
To install a local module using npm, it's important to understand how npm (Node Package Manager) works with local packages. npm allows you to manage and install various JavaScript packages and modules, whether they’re from a remote repository or locally on your system.
Installing a local module is particularly useful when you're developing a module or want to reuse custom packages across different projects without publishing them to the npm registry.
Why Do We Use Local Modules?
Local modules are essential when developing Node.js applications to include custom or in-progress functionality that isn't available on the npm registry. Using local modules allows developers to test and integrate their own code efficiently before publishing it or using it in different projects.
Installing local modules with NPM allows for better project management and modularity.
We have explained two methods to install local modules into an application. These methods will let you install a local module with no trouble.
Method 1: Install Local Modules Using npm-link
Step 1: Go to the local module directory ( package you want to install ) and enter this command.
npm link

Step 2: Go to the project directory where you want to install the local module and enter this command.
npm link package-name

Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
Method 2: Install Local Module Using npm install
We need to provide <folder> argument to npm install, The argument should be the local folder where the package is present, Path is the location of the folder containing the package ( local_module ) you want to install
npm install /path

Example: Let the path where your local module stored is C:\Users\engineer\Desktop\package. Now go the project directory and type the command npm install C:\Users\engineer\Desktop\package
NOTE: Just provide the package folder name but not the package name, it will automatically
link it to your project.
How to Uninstall a Package Installed with an npm link?
To uninstall a module linked globally using npm link, you can use the npm unlink command. Run this command in your project directory to remove the link to the local module:
The following command can be used to remove the globally connected foo kit
npm rm --global foo
Using local modules in Node.js can streamline development and testing processes. By understanding how to link and install these modules, you can efficiently manage dependencies and integrate custom code into your projects. Whether you choose npm link for its flexibility or npm install for direct folder installation, both methods are used in Node.js development.
Similar Reads
How to Install Node.js and npm on Ubuntu? If you're developing JavaScript applications on Ubuntu, knowing how to install Node.js on Ubuntu is essential. Node.js is a powerful runtime environment that enables server-side scripting, while npm, the Node Package Manager, allows you to manage your project's dependencies easily. This guide will w
7 min read
How to Install NPM FS in Node JS ? The file system module allows you to work with the file system on your computer NodeJS includes the fs module, to communicate with file systems. It provides functionality for interacting with the file system, such as reading from and writing to files, creating and removing directories, etc. The File
4 min read
How to install modules without npm in node.js ? We can install modules required for a particular project in node.js without npm, the recommended node package manager using yarn. Yarn is a wonderful package manager. Like npm, if you have a project folder with package.json containing all the required dependencies mentioned for the project, you can
3 min read
How to Install Node.js on Windows Installing Node.js on Windows is a straightforward process, but it's essential to follow the right steps to ensure smooth setup and proper functioning of Node Package Manager (NPM), which is crucial for managing dependencies and packages. This guide will walk you through the official site, NVM, Wind
6 min read
How to Install Node.js on a Webserver ? Node.js is a powerful, lightweight, and efficient runtime for executing JavaScript code on the server side. It is particularly well-suited for building scalable network applications. Installing Node.js on a web server enables developers to run server-side JavaScript, host web applications, and serve
2 min read
How to Install Node & Run NPM in VS Code? Node.js is an open-source, server-side JavaScript runtime environment built on the V8 engine. It allows developers to execute JavaScript code outside of a web browser. In this article, we will see how to install Node.js and NPM and install packages in VS Code using NPM. Steps to Install NodeJS and N
2 min read