npm command
- User
npm command
- Assistant
npm, which stands for Node Package Manager, is a command-line tool used to manage packages in Node.js and JavaScript projects. Here are some commonnpmcommands:-
Initialize a new project:
npm initThis command will create a
package.jsonfile in your project directory. You can usenpm init -yto skip the configuration questions and create a defaultpackage.json. -
Install a package:
npm install <package-name>This installs the specified package and adds it to your
node_modulesdirectory. If you want to save it as a dependency in yourpackage.json, you can use the--saveflag (though this is the default behavior for npm 5 and above). -
Install a package globally:
npm install -g <package-name>This installs the package globally on your system, allowing you to use it from anywhere in your terminal.
-
Uninstall a package:
npm uninstall <package-name>This removes the specified package from your project.
-
Update a package:
npm update <package-name> -
List installed packages:
npm listThis shows the currently installed packages in the local project. You can add
-gto list global packages (npm list -g). -
Check for outdated packages:
npm outdated -
Run a script defined in
package.json:npm run <script-name>This is used to run a script defined in the "scripts" section of your
package.jsonfile. -
Install all dependencies:
npm installThis installs all the dependencies listed in your
package.json. -
Update npm to the latest version:
npm install -g npm
These commands will help you manage your Node.js projects effectively using npm. If you're looking for a specific command or functionality, feel free to ask!
-