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