NPM Package Management
Jay Shankar
Associate Specialist - Tech at Synechron | ReactJS Professional | Project Management
npm (Node Package Manager) is the default package manager for Node.js, and it is widely used for managing JavaScript packages and dependencies. Here are some key concepts and common commands related to npm package management:
npm init
Follow the prompts to provide information about your project.
2. Install Dependencies:
- Install dependencies listed in the package.json file using:
npm install
?? - To install a specific package and add it as a dependency:
npm install package-name
3. Install Development Dependencies:
- To install packages that are only needed during development (e.g., testing frameworks), use:
npm install --save-dev package-name
4. Install Global Packages:
?? - Install a package globally to make it available across different projects:
npm install -g package-name
5. Save Dependencies to package.json:
?? - By default, npm install adds dependencies to the dependencies section of your package.json. To save a package as a development dependency, use the --save-dev flag.
6. Uninstall Packages:
?? - Remove a package from your project:
npm uninstall package-name
7. Check for Outdated Packages:
?? - Identify outdated packages:
npm outdated
8. Update Packages:
?? - Update packages to their latest versions:
领英推荐
npm update
9. Install a Specific Version:
?? - Install a specific version of a package:
npm install [email protected]
10. Semantic Versioning:
?- Understand and use semantic versioning (SemVer) when specifying package versions in your package.json.
11. Publish Packages:
??? - If you are the author of a package, you can publish it to the npm registry:
npm publish
12. Linking Local Packages:
??? - Link a local package (useful for development and testing):
npm link
13. Scripts:
??? - Define scripts in the scripts section of your package.json to automate common tasks. For example, you can define a script for running tests, starting your application, etc.
14. npm Registry:
??? - By default, npm installs packages from the npm registry. You can also use private registries or specify a custom registry.
15. npmrc Configuration:
??? - Configure npm behavior using the .npmrc file, including registry settings, proxy configurations, and more.
16. Lock Files:
??? - npm generates a package-lock.json file to lock down the versions of your project's dependencies.
17. Audit:
??? - Use the npm audit command to check for security vulnerabilities in your project's dependencies.
These are fundamental concepts and commands for working with npm.