How to install specified directory using npm ? - GeeksforGeeks

10 Feb, 2021
Node. js is a platform built on Chrome’s JavaScript v8 engine, which is used for easily building fast and scalable network applications, javascript uses an event-driven, non-blocking I/O model that makes it lightweight and efficient which is perfect for data-intensive real-time applications that run across distributed devices and to make use of the tools (or packages) in Node. js, we need to be able to install in our machine and manage them in a useful way. This is where npm, the Node package manager, comes in to play and it contains default packages and also allows us to install external packages in our project. We want to use and provides a user interface to work with them.
Installing npm to a specific directory using the following simple steps :
First, check if Node is installed on your pc or laptop. In order to check if Node is pre-installed or not open up a terminal in mac or command prompt in windows and type the following command :node -vNow, 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 then please refer this article and install node according to your PC requirement and version.Open up a javascript project in an editor and decide on which directory you want to install the npm package, we can also create a sub-directory and install our 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/directory we can use mkdir <folder name > and to make a sub-directory or sub-folder inside a directory/folder use command mkdir -p <folder name>. Here, I will be creating a directory named “new” under my “TEST” project folder in which I will install my npm package.So, I will be using the command in 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.Now, our final step to install 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 our npm package into a specific directory.npm install --prefix ./(folder/sub_folder_name) <package name>Installing npm package “animation” in the current directory and using below command:npm install --prefix ./new animationConsole Output: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:My Personal Notes
arrow_drop_upSave
First, check if Node is installed on your pc or laptop. In order to check if Node is pre-installed or not open up a terminal in mac or command prompt in windows and type the following command :node -vNow, 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 then please refer this article and install node according to your PC requirement and version.
First, check if Node is installed on your pc or laptop. In order to check if Node is pre-installed or not open up a terminal in mac or command prompt in windows and type the following command :
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 then please refer this article and install node according to your PC requirement and version.
Open up a javascript project in an editor and decide on which directory you want to install the npm package, we can also create a sub-directory and install our 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/directory we can use mkdir <folder name > and to make a sub-directory or sub-folder inside a directory/folder use command mkdir -p <folder name>. Here, I will be creating a directory named “new” under my “TEST” project folder in which I will install my npm package.So, I will be using the command in 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.
Open up a javascript project in an editor and decide on which directory you want to install the npm package, we can also create a sub-directory and install our 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/directory we can use mkdir <folder name > and to make a sub-directory or sub-folder inside a directory/folder use command mkdir -p <folder name>. Here, I will be creating a directory named “new” under my “TEST” project folder in which I will install my npm package.So, I will be using the command in 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.
Now, our final step to install 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 our npm package into a specific directory.npm install --prefix ./(folder/sub_folder_name) <package name>Installing npm package “animation” in the current directory and using below command:npm install --prefix ./new animationConsole Output: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:My Personal Notes
arrow_drop_upSave
Now, our final step to install 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 our npm package into a specific directory.
npm install --prefix ./(folder/sub_folder_name) <package name>
Installing npm package “animation” in the current directory and using below command:
npm install --prefix ./new animation
Console Output:
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:
Node-npm
Picked
Technical Scripter 2020
Node.js
Technical Scripter
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between dependencies, devDependencies and peerDependencies
How to connect Node.js with React.js ?
Node.js Export Module
Mongoose find() Function
Mongoose Populate() Method
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Difference between var, let and const keywords in JavaScript