beginner
cli-tool
cross-platform
javascript
package-management
npm Package Manager
_ Copiar todos los comandos
Generar PDF
Instrucciones y flujos de trabajo para el desarrollo de JavaScript y Node.js.
Instalación > Configuración
Install Node.js and npm
# Using Node Version Manager (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh| bash
nvm install node
nvm use node
# Direct download from nodejs.org
# Or using package managers:
# macOS: brew install node
# Ubuntu: sudo apt install nodejs npm
# Windows: choco install nodejs
Operaciones básicas del paquete
Command
Description
INLINE_CODE_8
Install package locally
INLINE_CODE_9
Install package globally
INLINE_CODE_10
Uninstall package
INLINE_CODE_11
Update all packages
INLINE_CODE_12
Update specific package
INLINE_CODE_13
List installed packages
INLINE_CODE_14
List global packages
_
## Project Management
Iniciación del proyecto
Command
Description
INLINE_CODE_15
Initialize new project
INLINE_CODE_16
Initialize with defaults
INLINE_CODE_17
Initialize with scoped template
INLINE_CODE_18
Create project with template
Administración de dependencia
Command
Description
INLINE_CODE_19
Install all dependencies
INLINE_CODE_20
Install and save to dependencies
INLINE_CODE_21
Install and save to devDependencies
INLINE_CODE_22
Install as optional dependency
INLINE_CODE_23
Install without saving
Command
Description
INLINE_CODE_24
Search for packages
INLINE_CODE_25
Show package information
INLINE_CODE_26
View package details
INLINE_CODE_27
Show outdated packages
INLINE_CODE_28
Check for vulnerabilities
INLINE_CODE_29
Fix vulnerabilities
_
## Scripts and Execution
Script Management
Command
Description
INLINE_CODE_30
Run custom script
INLINE_CODE_31
Run start script
INLINE_CODE_32
Run test script
INLINE_CODE_33
Run build script
INLINE_CODE_34
Run development script
_
### Ejemplo paquete.json Scripts
\\\\ {
"scripts" : \\\\ {
"start" : "node server.js" ,
"dev" : "nodemon server.js" ,
"build" : "webpack --mode production" ,
"test" : "jest" ,
"lint" : "eslint src/" ,
"format" : "prettier --write src/"
\\\\ }
\\\\ }
Version Management
Versión semántica
Command
Description
INLINE_CODE_35
Increment patch version
INLINE_CODE_36
Increment minor version
INLINE_CODE_37
Increment major version
INLINE_CODE_38
Create prerelease version
_
### Package Instalación por versión
Command
Description
---------
-------------
INLINE_CODE_39
Install specific version
INLINE_CODE_40
Install latest version
INLINE_CODE_41
Install next/beta version
INLINE_CODE_42
Install compatible version
_
## Configuración
npm Configuration
Command
Description
INLINE_CODE_43
Show configuration
INLINE_CODE_44
Get configuration value
INLINE_CODE_45
Set configuration value
INLINE_CODE_46
Delete configuration
_
### Configuración común
Setting
Description
---------
-------------
INLINE_CODE_47
Set registry
INLINE_CODE_48
Set default author
INLINE_CODE_49
Set default license
INLINE_CODE_50
Save exact versions
.npmrc File
# Project .npmrc
registry = https://registry.npmjs.org/
save-exact = true
engine-strict = true
fund = false
audit-level = moderate
# Global .npmrc (~/.npmrc)
init-author-name = Your Name
init-author-email = your.email@example.com
init-license = MIT
Publishing
Paquete Publishing
Command
Description
INLINE_CODE_51
Login to npm registry
INLINE_CODE_52
Check logged in user
INLINE_CODE_53
Publish package
INLINE_CODE_54
Publish scoped package publicly
INLINE_CODE_55
Unpublish specific version
_
### Publishing Workflow
# 1. Update version
npm version patch
# 2. Build package
npm run build
# 3. Test package
npm test
# 4. Publish
npm publish
# 5. Tag release
git tag v1.0.0
git push origin v1.0.0
Advanced Usage
Espacios de trabajo (npm 7+)
\\\\ {
"name" : "my-monorepo" ,
"workspaces" : [
"packages/*" ,
"apps/*"
]
\\\\ }
Command
Description
INLINE_CODE_56
Install all workspace dependencies
INLINE_CODE_57
Run tests in all workspaces
INLINE_CODE_58
Run command in specific workspace
Package Linking
Command
Description
INLINE_CODE_59
Create global link
INLINE_CODE_60
Link to global package
INLINE_CODE_61
Unlink package
Cache Management
Command
Description
INLINE_CODE_62
Verify cache integrity
INLINE_CODE_63
Clear cache
INLINE_CODE_64
List cached packages
Seguridad
Security Auditing
Command
Description
INLINE_CODE_65
Check for vulnerabilities
INLINE_CODE_66
Check high severity only
INLINE_CODE_67
Fix vulnerabilities automatically
INLINE_CODE_68
Force fix (may break changes)
Package Verification
Command
Description
INLINE_CODE_69
Create tarball
INLINE_CODE_70
Show what would be packed
INLINE_CODE_71
Install from tarball
_
## Performance Optimization
Faster Instalación
# Use npm ci for CI/CD
npm ci
# Parallel installation
npm install --prefer-offline
# Skip optional dependencies
npm install --no-optional
# Production only
npm install --production
Administradores de paquetes alternativos
Manager
Installation
Benefits
Yarn
INLINE_CODE_72
Faster, deterministic
pnpm
INLINE_CODE_73
Disk space efficient
Bun
INLINE_CODE_74
Extremely fast
Troubleshooting
Problemas comunes
Problem
Solution
Permission errors
Use nvm or fix permissions
Package conflicts
Delete node_modules and reinstall
Outdated npm
INLINE_CODE_75
Registry issues
INLINE_CODE_76
_
## Debugging
Command
Description
---------
-------------
INLINE_CODE_77
Check npm environment
INLINE_CODE_78
Check dependency tree
INLINE_CODE_79
Show top-level dependencies
INLINE_CODE_80
Show why package is installed
Reset and Clean Install
# Clean install
rm -rf node_modules package-lock.json
npm install
# Clear npm cache
npm cache clean --force
# Reset npm configuration
npm config edit
Buenas prácticas
Package.json Gestión
\\\\ {
"name" : "my-project" ,
"version" : "1.0.0" ,
"description" : "Project description" ,
"main" : "index.js" ,
"engines" : \\\\ {
"node" : ">=16.0.0" ,
"npm" : ">=8.0.0"
\\\\ },
"dependencies" : \\\\ {
"express" : "^4.18.0"
\\\\ },
"devDependencies" : \\\\ {
"jest" : "^29.0.0" ,
"eslint" : "^8.0.0"
\\\\ },
"peerDependencies" : \\\\ {
"react" : ">=16.0.0"
\\\\ }
\\\\ }
Development Workflow
Version Pinning : Usar versiones exactas para dependencias críticas
Lock Files : Commit package-lock.json to version control
Seguridad : Auditorías periódicas de seguridad con npm audit
Testing : Test before publishing with npm pack
Documentación : Mantener una README integral
CI/CD : Uso npm ci en integración continua
Caching : Leverage npm cache in CI environments
Instalación selectiva : Uso --production para construcciones de producción
** Gestores alternativos**: Considerar hilo o pnpm para grandes proyectos
Registry : Use registro privado para paquetes internos