How To Install Specified Directory Using NPM? (original) (raw)

Last Updated : 23 Jul, 2025

To install a specified directory using npm, you can use npm’s ability to install local modules directly from a directory on your machine. This is particularly useful when you're working with custom packages, private modules, or developing a project across multiple repositories and need to share a module that hasn't been published to the npm registry.

In this article, we will explore how to install a package from a local directory using npm, and how this helps in sharing local modules across projects or testing packages before publishing them to the npm registry.

Why Install a Directory Using npm?

There are several cases where installing a module from a directory is useful:

**Steps to Install npm To A Specific Directory

**Step 1: Check if Node is installed or not in your system.

node -v

Now, if the Node version is displayed something like "

**v12.18.3"

then you may conclude that Node is pre-installed on the PC or laptop, if not installation of Node.js on Windows according to your PC requirement and version and you can also install the previous version of node.js.

**Step 2: Open up a javascript project in an editor in which you want to install the npm package.

**To create a sub-directory: We can also create a sub-directory and install npm packages. To create a sub-directory ****"cd"(change directory)** into the project directory and make use of **mkdir command.

**To create a new folder: To create a new Folder/directory we can use **mkdir and to make a sub-directory or sub-folder inside a directory/folder use the command mkdir -p .

Here, we will be creating a directory named ****"new"** under the "**TEST" project folder in which will install the npm package. So, we will be using the command in the terminal "**mkdir -p new" once our directory in the terminal is set to our Project directory i.e ****"TEST"** and we can see our project files are structured somewhat in this manner under the "**TEST" main directory.

Folder Structure

**Step 3: Now, our final step to install npm to a specific directory will be to make use of the **--prefix option, Here we will be making use of the following command to install npm to a specific directory.

npm install --prefix ./(folder/sub_folder_name)

Installing npm package "**animation" in the current directory and using below command:

npm install --prefix ./new animation

**Output:

Install Specified Directory Using NPM

Now, as we have installed our required npm package into our desired sub-directory i.e ****"new",** we can check our ****"new"** directory by opening it and we can see that the following package is successfully installed into the directory.

**Updated Project structure:

Updated Folder Structure

Also Read