
npm Install Command
The npm install
command is used to install packages and dependencies from the npm registry. It is commonly used in JavaScript projects to fetch and install external libraries, frameworks, and tools required for the project.
To use the npm install
command, open a terminal or command prompt and navigate to the root directory of your project. Then, run the following command:
npm install <package-name>
Replace <package-name>
with the name of the package you want to install. This can be the name of a specific package or a package with a specific version number. For example:
npm install lodash
npm install [email protected]
If the package is available in the npm registry, npm will download and install it along with its dependencies. The installed packages are typically placed in a node_modules
directory within your project.
You can also specify multiple packages to install in a single command:
npm install package1 package2 package3
To save the installed packages as dependencies in your package.json
file, you can use the --save
or -S
flag:
npm install <package-name> --save
The --save
flag will add the package as a regular dependency, while the --save-dev
or -D
flag will add it as a development dependency:
npm install <package-name> --save-dev
You can also specify the package version using the --save-exact
flag:
npm install <package-name> --save-exact
This will save the exact version of the package in the package.json
file.
Additionally, you can install packages globally by using the -g
flag:
npm install -g <package-name>
This will install the package globally on your system, making it available for use in any project.
The npm install
command is a powerful tool for managing dependencies in JavaScript projects, and it provides various options and flags to control the installation behavior. Make sure to refer to the official npm documentation for more details on how to use the command and its available options.