# node.js [Node.js](https://nodejs.org/fr/)® est un environnement d’exécution JavaScript construit sur le [moteur JavaScript V8 de Chrome](https://developers.google.com/v8/). [npm](https://www.npmjs.com) est un gestionnaire de paquets pour JavaScript automatiquement installé avec Node. [nvm](https://github.com/creationix/nvm) (Node Version Manager) est un gestionnaire de version de Node. ### Installation (Homebrew): ```bash # installer node et npm $ brew install node ``` ### Installation (directe): Installer [Node.js](https://nodejs.org/en/download/) (version LTS) ### Installation ([nvm](nvm.md)): ```bash $ brew install nvm # installer Node 8 $ nvm install 8 # installer Node 10 $ nvm install 10 ``` ### npm npm est un gestionnaire de paquets pour JavaScript automatiquement installé avec Node. #### Version de npm: ```bash # version: $ node -v v9.5.0 $ npm -v 5.6.0 ``` #### Update: ```bash $ npm install npm@latest -g $ brew install node $ npm install npm --global ``` https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory #### Local: Installer npm packages localement => `/Users/bruno/Sites/node_modules` - Installer: `npm install ` - Mise-à-jour: `npm update` (depuis le répertoire du module) - Desinstaller: `npm uninstall ` Mises à jour disponibles: ```bash bruno@silverbook:~/Sites/node_modules$ npm outdated Package Current Wanted Latest Location jquery MISSING 3.2.1 3.2.1 livephotoskit 1.4.11 1.5.2 1.5.2 ``` `npm outdated` montre plusieurs choses: 1. Current: la version actuelle du module. 2. Wanted: la dernière version qui satisfait le semver ranges decrit dans le package.json 3. Latest: la toute dernière version du module disponible sur npm. Mettre-à-jour: ```bash $ npm outdated | awk '{print $1}' | xargs npm update ``` #### Global: Installer npm packages globalement => `/usr/local/lib/node_modules/` - Installer: `npm install -g ` - Mise-à-jour: `npm update -g ` - Désinstaller: `npm uninstall -g ` #### npm verb outdated not updating @angular/cli because it's currently at the maximum version that matches its specified semver range: [Stackoverflow](https://stackoverflow.com/questions/39758042/npm-update-does-not-do-anything) [semver range](https://docs.npmjs.com/misc/semver#advanced-range-syntax) ```bash $ npm update -g --verbose @angular/cli npm verb outdated not updating rxjs because it's currently at the maximum version that matches its specified semver range ``` #### Plus info sur une commande: ```bash # Mode verbose: $ npm update -g --verbose # Exécute la commande sans rien installer: $ npm install -g --dry-run ``` #### Aller dans node_modules: ```bash bruno@SilverBook:~$ cd Sites/node_modules/ ``` puis - Liste package installé: `npm ls` `npm list -g --depth=0` - Mises à jour disponibles: `npm outdated` - Installer une m-à-j: `npm update` - Installer un package: `npm install package` - Désinstaller un package: `npm uninstall package` #### Voir toutes les versions disponibles d'un module: ```bash # Option: --json $ npm show @popperjs/core versions [ '2.0.0-alpha.1', '2.0.0-alpha.2', '2.0.0-alpha.3', '2.0.0-alpha.4', '2.0.0-next.5', '2.0.0-next.6', '2.0.0-next.7', '2.0.0-next.8', '2.0.0-next.9', '2.0.0-next.10', '2.0.0-next.11', '2.0.0-next.12', '2.0.0-next.13', '2.0.0-next.14', '2.0.0-next.15', '2.0.0-next.16', '2.0.0-next.17', '2.0.0-rc.1', '2.0.0-rc.2', '2.0.0-rc.3', '2.0.0', '2.0.1', '2.0.2', '2.0.3', '2.0.4', '2.0.5', '2.0.6', '2.1.0', '2.1.1', '2.2.0-bundlephobia.1', '2.2.0', '2.2.1', '2.2.2', '2.2.3', '2.3.0', '2.3.1', '2.3.2', '2.3.3', '2.4.0', '2.4.1', '2.4.2', '2.4.3', '2.4.4', '2.5.0', '2.5.1', '2.5.2', '2.5.3', '2.5.4', '2.6.0', '2.7.0', '2.7.1', '2.7.2', '2.8.0', '2.8.1', '2.8.2', '2.8.3', '2.8.4', '2.8.5', '2.8.6', '2.9.0', '2.9.1', '2.9.2' ] ``` ```bash # Sans les versions alpha et beta $ npm show bootstrap@* version # bash OK, zsh NOK ``` `"dependencies": { "express": "2.9.1" }` (major.minor.patch) - major version: 2 - minor version: 9 - patch version: 1 #### Installer un module: Installer une version spécifique: ```bash $ npm info @popperjs/core @popperjs/core@2.9.2 | MIT | deps: none | versions: 62 Tooltip and Popover Positioning Engine https://github.com/popperjs/popper-core#readme dist-tags: latest: 2.9.2 # Version spécifique (@x.y.z) $ npm install @popperjs/core@2.8.0 $ npm ls Downloads@ /Users/bruno/Downloads └── @popperjs/core@2.8.0 ``` Installer latest minor version: ```bash $ npm info @popperjs/core @popperjs/core@2.9.2 | MIT | deps: none | versions: 62 Tooltip and Popover Positioning Engine https://github.com/popperjs/popper-core#readme dist-tags: latest: 2.9.2 # Latest minor version (^) # Update to 2.*.* $ npm install @popperjs/core@^2.8.0 $ npm ls Downloads@ /Users/bruno/Downloads └── @popperjs/core@2.9.2 ``` Installer latest patch version: ```bash $ npm info @popperjs/core @popperjs/core@2.9.2 | MIT | deps: none | versions: 62 Tooltip and Popover Positioning Engine https://github.com/popperjs/popper-core#readme dist-tags: latest: 2.9.2 # Latest patch version (~) # Update to 2.8.* $ npm install @popperjs/core@~2.8.0 $ npm ls Downloads@ /Users/bruno/Downloads └── @popperjs/core@2.8.6 ``` Installer la dernière version: ```bash $ npm info @popperjs/core @popperjs/core@2.9.2 | MIT | deps: none | versions: 62 Tooltip and Popover Positioning Engine https://github.com/popperjs/popper-core#readme dist-tags: latest: 2.9.2 # Dernière version (@latest) $ npm install @popperjs/core@latest $npm ls Downloads@ /Users/bruno/Downloads └── @popperjs/core@2.9.2 ``` #### Supprimer tous les modules: ```bash $ for package in `ls node_modules`; do npm uninstall $package; done; ``` #### Maintenance: ```bash $ npm doctor npm WARN verifyCachedFiles Content garbage-collected: 46 (4358853 bytes) npm WARN verifyCachedFiles Cache issues have been fixed Check Value Recommendation npm ping OK npm -v v5.10.0 Use npm v6.4.1 node -v v8.11.4 npm config get registry https://registry.npmjs.org/ which git /usr/bin/git Perms check on cached files ok Perms check on global node_modules ok Perms check on local node_modules ok Verify cache contents verified 2159 tarballs ``` #### Info sur un package: ```bash $ npm show cli # idem: # npm info cli # npm view cli cli@1.0.1 | MIT | deps: 2 | versions: 59 A tool for rapidly building command line apps http://github.com/node-js-libs/cli keywords: cli, command line, opts, parseopt, opt, args, console, argsparse, optparse, autocomplete, command, autocompletion dist .tarball: https://registry.npmjs.org/cli/-/cli-1.0.1.tgz .shasum: 22817534f24bfa4950c34d532d48ecbc621b8c14 dependencies: exit: 0.1.2 glob: ^7.1.1 maintainers: - cohara87 dist-tags: latest: 1.0.1 published over a year ago by cohara87 ``` #### Version d'un package installé: ```bash $ npm list bootstrap silverbook.local@1.0.0 /Users/bruno/Sites └── bootstrap@5.0.1 ``` #### Dernière version d'un package: ```bash $ npm view bootstrap version 5.0.1 ``` #### Rechercher un package: [npms.io](https://npms.io) [Libraries.io](https://libraries.io/search?platforms=NPM) ```bash $ npm search tar NAME | DESCRIPTION | AUTHOR | DATE | VERSION | KEYWORDS tar | tar for node | =nlf… | 2020-08-14 | 6.0.5 | tar-fs | filesystem bindings… | =mafintosh… | 2020-11-06 | 2.1.1 | tar fs file tarball directory stream tar-stream | tar-stream is a… | =mafintosh… | 2020-09-10 | 2.1.4 | tar tarball parse parser generate generator stream stream2 streams streams2 str archiver | a streaming… | =ctalkington | 2020-09-11 | 5.0.2 | archive archiver stream zip tar ``` #### Funding: ```bash 2 packages are looking for funding run `npm fund` for details ``` Ce message apparait généralement après la m-à-j d'un package tel Angular, React, Vue... Il demande de lancer la commande `npm fund` pour lister les packages qui demandent des fonds pour continuer leur développement. ```bash ~/Sites/node_modules master* ⇡ ❯ npm fund /Users/bruno/Sites ├─┬ https://opencollective.com/bootstrap │ └── bootstrap@4.5.2 └─┬ https://opencollective.com/popperjs └── popper.js@1.16.1 ``` Pour éviter ce message: ```bash # à l'installation: npm install --no-fund # configuration globale npm config set fund false --global # configuration par package: npm config set fund false ``` #### Erreur *"No matching version found for tar@^6.0.5"*: ```bash $ npm install -g --unsafe-perm homebridge-config-ui-x npm ERR! code ETARGET npm ERR! notarget No matching version found for tar@^6.0.5. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. ``` ```bash $ npm info tar tar@6.0.5 | ISC | deps: 6 | versions: 88 tar for node https://github.com/npm/node-tar#readme dist .tarball: https://registry.npmjs.org/tar/-/tar-6.0.5.tgz ``` ```bash $ npm install https://github.com/npm/node-tar/tarball/v6.0.5 --save npm ERR! code ETARGET npm ERR! notarget No matching version found for minizlib@^2.1.1. ``` ```bash $ npm info minizlib minizlib@2.1.2 | MIT | deps: 2 | versions: 20 A small fast zlib stream built on [minipass](http://npm.im/minipass) and Node.js's zlib binding. https://github.com/isaacs/minizlib#readme ``` ```bash $ npm install https://github.com/isaacs/minizlib/tarball/v2.1.1 --save ``` ```bash $ npm install https://github.com/npm/node-tar/tarball/v6.0.5 --save ``` ```bash $ npm install -g --unsafe-perm homebridge-config-ui-x added 362 packages, and audited 362 packages in 45s ``` Autre solution: ```bash $ npm cache clean --force ``` #### Packages: ##### uninstall-all-modules Desinstaller tous les modules= ```bash $ npm uninstall ``` ##### livephotoskit, jquery, picturefill