Vai al contenuto

npm Package Manager

Traduzione: Copia tutti i comandi Traduzione: Generare PDF < > Comandi e flussi di lavoro completi npm (Node Package Manager) per lo sviluppo JavaScript e Node.js. ## Installazione e configurazione ### Installare Node.js e npm Traduzione: ### Operazioni di pacchetti di base | | Command | Description | | | --- | --- | | | `npm install package_name` | Install package locally | | | | `npm install -g package_name` | Install package globally | | | | `npm uninstall package_name` | Uninstall package | | | | `npm update` | Update all packages | | | | `npm update package_name` | Update specific package | | | | `npm list` | List installed packages | | | | `npm list -g` | List global packages | | ## Gestione dei progetti ### Inizializzazione del progetto | | Command | Description | | | --- | --- | | | `npm init` | Initialize new project | | | | `npm init -y` | Initialize with defaults | | | | `npm init @scope` | Initialize with scoped template | | | | `npm create package_name` | Create project with template | | ### Gestione delle dipendenze | | Command | Description | | | --- | --- | | | `npm install` | Install all dependencies | | | | `npm install --save package` | Install and save to dependencies | | | | `npm install --save-dev package` | Install and save to devDependencies | | | | `npm install --save-optional package` | Install as optional dependency | | | | `npm install --no-save package` | Install without saving | | ### Informazioni sul pacchetto | | Command | Description | | | --- | --- | | | `npm search keyword` | Search for packages | | | | `npm info package_name` | Show package information | | | | `npm view package_name` | View package details | | | | `npm outdated` | Show outdated packages | | | | `npm audit` | Check for vulnerabilities | | | | `npm audit fix` | Fix vulnerabilities | | ## Script e esecuzione ### Gestione script | | Command | Description | | | --- | --- | | | `npm run script_name` | Run custom script | | | | `npm start` | Run start script | | | | `npm test` | Run test script | | | | `npm run build` | Run build script | | | | `npm run dev` | Run development script | | ### Esempio pacchetto.json Scripts Traduzione: ## Gestione della versione ### Versione semantica | | Command | Description | | | --- | --- | | | `npm version patch` | Increment patch version | | | | `npm version minor` | Increment minor version | | | | `npm version major` | Increment major version | | | | `npm version prerelease` | Create prerelease version | | ### Pacchetto Installazione per versione | | Command | Description | | | --- | --- | | | `npm install package@1.2.3` | Install specific version | | | | `npm install package@latest` | Install latest version | | | | `npm install package@next` | Install next/beta version | | | | `npm install package@^1.2.0` | Install compatible version | | ## Configurazione ### Configurazione npm | | Command | Description | | | --- | --- | | | `npm config list` | Show configuration | | | | `npm config get key` | Get configuration value | | | | `npm config set key value` | Set configuration value | | | | `npm config delete key` | Delete configuration | | ### Configurazione comune | | Setting | Description | | | --- | --- | | | `npm config set registry https://registry.npmjs.org/` | Set registry | | | | `npm config set init-author-name "Your Name"` | Set default author | | | | `npm config set init-license "MIT"` | Set default license | | | | `npm config set save-exact true` | Save exact versions | | ### .npmrc File Traduzione: ## Pubblicazione ### Pacchetto Pubblicazione | | Command | Description | | | --- | --- | | | `npm login` | Login to npm registry | | | | `npm whoami` | Check logged in user | | | | `npm publish` | Publish package | | | | `npm publish --access public` | Publish scoped package publicly | | | | `npm unpublish package@version` | Unpublish specific version | | ### Flusso di lavoro editoriale Traduzione: ## Uso avanzato ### Spazi di lavoro (npm 7+) Traduzione: | | Command | Description | | | --- | --- | | | `npm install --workspaces` | Install all workspace dependencies | | | | `npm run test --workspaces` | Run tests in all workspaces | | | | `npm run build --workspace=package-a` | Run command in specific workspace | | ### Pacchetto di collegamento | | Command | Description | | | --- | --- | | | `npm link` | Create global link | | | | `npm link package_name` | Link to global package | | | | `npm unlink package_name` | Unlink package | | ### Gestione della cache | | Command | Description | | | --- | --- | | | `npm cache verify` | Verify cache integrity | | | | `npm cache clean --force` | Clear cache | | | | `npm cache ls` | List cached packages | | ## Sicurezza ### Audizione di sicurezza | | Command | Description | | | --- | --- | | | `npm audit` | Check for vulnerabilities | | | | `npm audit --audit-level high` | Check high severity only | | | | `npm audit fix` | Fix vulnerabilities automatically | | | | `npm audit fix --force` | Force fix (may break changes) | | ### Verifica dei pacchetti | | Command | Description | | | --- | --- | | | `npm pack` | Create tarball | | | | `npm pack --dry-run` | Show what would be packed | | | | `npm install package.tgz` | Install from tarball | | ## Ottimizzazione delle prestazioni ### Installazione più veloce Traduzione: ### Gestione dei pacchetti alternativi | | Manager | Installation | Benefits | | | --- | --- | --- | | | **Yarn** | `npm install -g yarn` | Faster, deterministic | | | | **pnpm** | `npm install -g pnpm` | Disk space efficient | | | | **Bun** | `curl -fsSL https://bun.sh/install \ | bash` | Extremely fast | | ## Risoluzione dei problemi ### Questioni comuni | | Problem | Solution | | | --- | --- | | | Permission errors | Use nvm or fix permissions | | | | Package conflicts | Delete node_modules and reinstall | | | | Outdated npm | `npm install -g npm@latest` | | | | Registry issues | `npm config set registry https://registry.npmjs.org/` | | ### Debug | | Command | Description | | | --- | --- | | | `npm doctor` | Check npm environment | | | | `npm ls` | Check dependency tree | | | | `npm ls --depth=0` | Show top-level dependencies | | | | `npm why package_name` | Show why package is installed | | ### Reset e Clean Install Traduzione: ## Migliori Pratiche ### Pacchetto.json Gestione Traduzione: ### Flusso di lavoro 1. # Version Pinning # Utilizzare versioni esatte per le dipendenze critiche 2. **Lock Files**: Commit package-lock.json al controllo della versione 3. **Sicurezza**: controlli di sicurezza regolari con `npm audit` 4. **Testing**: Prova prima di pubblicare con `npm pack` 5. **Documentazione**: Mantenere il README completo ### Prestazioni 1. **CI/CD**: Utilizzare `npm ci`_ in continua integrazione 2. **Caching**: cache Leverage npm in ambienti CI 3. ** Installazione selettiva**: Utilizzare `--production` per le costruzioni di produzione 4. **Responsabili alternativi**: Considerare filati o pnpm per grandi progetti 5. **Registry**: Utilizzare il registro privato per i pacchetti interni