by Sai gowtham

How to install npm packages to a specified directory

Learn, how to install npm packages to a specified directory in your project.

Normally, when we run an npm install package-name command, npm will install the packages in a default directory (node_modules folder).

To install the packages into a specified directory, we need to use the --prefix option followed by the directory path.

Example:

npm install --prefix ./my-app react

This above command will install a react package into the my-app folder.

Note: If the specified directory doesn’t exist, npm will create it automatically.

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
26,545 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
221,520 students enrolled
44 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
114,575 students enrolled
21 hours of video content
View Course