# 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 toutederniè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` #### 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 ``` #### 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 ``` #### Packages: [Rechercher un package](https://npms.io) ```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 ``` ##### uninstall-all-modules Desinstaller tous les modules= ```bash $ npm uninstall ``` ##### livephotoskit, jquery, picturefill