Basic npm Commands Guide
Installing Packages Locally and Globally
Installing Locally:
To install a package locally, meaning it is specific to your current project, use the following command:
npm install <package-name>Example:
npm install lodashThis installs the "lodash" package and adds it to your project's node_modules folder.
Installing Globally:
To install a package globally, making it available across your entire system, use the -g flag:
npm install -g <package-name>Example:
npm install -g nodemonThis installs "nodemon" globally, allowing you to use it as a command-line tool.
Updating and Uninstalling Packages
Updating Packages:
To update a package to its latest version, use the following command:
npm update <package-name>Example:
npm update lodashThis updates the "lodash" package to its latest version.
Uninstalling Packages:
To uninstall a package, removing it from your project or system, use the following command:
npm uninstall <package-name>Example:
npm uninstall nodemonThis removes the globally installed "nodemon" package.
Uninstalling Globally:
To uninstall a globally installed package, use the -g flag:
npm uninstall -g <package-name>Example:
npm uninstall -g nodemonThis removes the globally installed "nodemon" package.
These basic npm commands empower developers to manage packages effectively, whether they're working on a specific project or making tools available system-wide. Understanding these commands is fundamental for a smooth development experience and maintaining up-to-date and well-organized projects.