Files
mkdocs/docs/macos/node/node-js.md
2021-02-04 09:55:26 +01:00

7.3 KiB
Raw Blame History

node.js

Node.js® est un environnement dexécution JavaScript construit sur le moteur JavaScript V8 de Chrome.

npm est un gestionnaire de paquets pour JavaScript automatiquement installé avec Node.

nvm (Node Version Manager) est un gestionnaire de version de Node.

Installation (Homebrew):

# installer node et npm

$ brew install node

Installation (directe):

Installer Node.js (version LTS)

Installation (nvm):

$ 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:

# version:
$ node -v
v9.5.0
$ npm -v
5.6.0

Update:

$ 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 <package_name>
  • Mise-à-jour: npm update (depuis le répertoire du module)
  • Desinstaller: npm uninstall <package_name>

Mises à jour disponibles:

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:

$ npm outdated | awk '{print $1}' | xargs npm update

Global:

Installer npm packages globalement => /usr/local/lib/node_modules/

  • Installer: npm install -g <package_name>
  • Mise-à-jour: npm update -g <package_name>
  • Désinstaller: npm uninstall -g <package_name>

npm verb outdated not updating @angular/cli because it's currently at the maximum version that matches its specified semver range:

Stackoverflow semver range

$ 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:

# Mode verbose:
$ npm update -g --verbose

# Exécute la commande sans rien installer:
$ npm install -g --dry-run

Aller dans node_modules:

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:

$ for package in `ls node_modules`; do npm uninstall $package; done;

Maintenance:

$ 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:

$ 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 <cohara87@gmail.com>

dist-tags:
latest: 1.0.1

published over a year ago by cohara87 <cohara87@gmail.com>

Funding:

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.

~/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:

# à l'installation:
npm install --no-fund <package>  

# 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":

$ 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.
$ 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
$ 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.
$ 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
$ npm install https://github.com/isaacs/minizlib/tarball/v2.1.1 --save
$ npm install https://github.com/npm/node-tar/tarball/v6.0.5 --save
$ npm install -g --unsafe-perm homebridge-config-ui-x

added 362 packages, and audited 362 packages in 45s

Packages:

Rechercher un package

$ 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=

$ npm uninstall
livephotoskit, jquery, picturefill