Open In App
Related Articles

How to Install a Local Module Using npm?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

This article shows how to install a local module using npm. Local modules are modules created locally in your Node JS application to create user-required functionality. These local modules include different functionalities of your application in separate files and folders. To link the local module first you must have the local module directory or package directory. 

Before knowing how to install a local module using npm, let’s know why we use local modules.

Why Do We Use Local Modules?

We use local modules to create the user-required functionality in an application made using Node.js. npm (Node Package Manager) is the default package manager for Node.

How to Install Local Modules?

We have explained two methods to install local modules into an application. These methods will let you install a local module with no trouble.

 Step 1: Go to the local module directory ( package you want to install ) and enter this command.

npm link

Install-local-Module-Using-npm-link_1

Step 2: Go to the project directory where you want to install the local module and enter this command.  

npm link package-name

Install-local-Module-Using-npm-link_2

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

Install-Local-Module-Using-npm-install_1

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.

The program may be uninstalled using the same uninstall or rm order as is used to delete installed packages. The only thing to note is that the connection must be uninstalled globally the global flag must be defined.

The following command can be used to remove the globally connected foo kit

npm rm --global foo

Also Read


Last Updated : 08 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads