Tech talks: NPM dependencies
A summary of an Instea tech talk on npm version 2, covering dependency management, semantic versioning, devDependencies, and best practices for JavaScript projects.
This technical presentation focuses on npm version 2 with emphasis on managing project dependencies. The guide covers both server-side and client-side JavaScript dependency handling for tools like React and Webpack.
Basics
- Initialize projects using
npm initto createpackage.json - Install dependencies with
npm install <package-name> --save - The
--saveflag updatespackage.jsonautomatically - npm handles transitive dependencies automatically
Collaboration
- Team members install dependencies via
npm install - Unused dependencies flagged with
npm ls - Remove extraneous packages using
npm prune
Version Management
- Check outdated packages with
npm outdated - Update dependencies using
npm update --save - npm follows semantic versioning conventions
- Caret syntax
^2.10.6allows non-breaking updates
Dependency Types
- devDependencies: Testing and development tools (installed with
--save-dev) - Global dependencies: System-wide utilities (not recommended for project management)
- Scripts: Execute local tools via
package.jsonscripts section
Code Examples
npm install async --save
npm outdated
npm update --save
npm run lint -- --format compactRecommendation
Maintain all project dependencies locally in package.json rather than installing globally to ensure consistency across different projects.