Knowledge base
es
es
  • Base de conocimiento
  • Bash scripting
    • Echemos un vistazo
  • Jenkins
    • Echemos un vistazo
  • Kafka
    • Echemos un vistazo
  • Kubernetes / Docker
    • Echemos un vistazo
  • Node.js
    • Echemos un vistazo
    • Node binary executable
      • Evaluando dinámicamente el código
      • Precarga de módulos
      • Límite de pila de datos (Stack trace)
    • Depuración y diagnóstico
    • Enfoque práctico de javascript
      • Tipos de datos
      • Funciones
      • Herencia de prototipos
        • Funcional
        • Funciones de constructor
        • Constructor (Class-Syntax)
      • Closure scope
    • Paquetes y dependencias
      • Inicializando paquetes
      • Dependencias
      • Package scripts
    • Sistema de módulos
    • Flujo de control asíncrono
      • Callbacks
      • Promises
      • Async/await
  • OAuth 2.0 / OpenID Connect
    • Echemos un vistazo
    • OpenID Connect
    • OAuth 2.0
      • Mejores prácticas de cómo manejar tokens
  • OpenShift
    • Echemos un vistazo
  • OWASP
    • Echemos un vistazo
  • SAML 2.0
    • Echemos un vistazo
  • SSL / TLS
    • Echemos un vistazo
  • Terraform
    • Echemos un vistazo
Powered by GitBook
On this page

Was this helpful?

  1. Node.js
  2. Paquetes y dependencias

Inicializando paquetes

Comando npm

npm help muestra la lista de comandos disponibles:

➜  ~ npm help

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/danimerida2000/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.14.14 /opt/homebrew/Cellar/node@12/12.22.5/lib/node_modules/npm

El argumento -h nos muestra la referencia de ayuda de un comando:

➜  ~ npm install -h

npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <alias>@npm:<name>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>

aliases: i, isntall, add
common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]

Un paquete (aplicación/servicio) es una carpeta con un archivo package.json.

El comando npm init es utilizado para crear el archivo package.json.

Ejemplo:

➜  package-test npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (package-test) project-test
version: (1.0.0) 0.1.0
description: Project test
entry point: (index.js) app.js
test command:
git repository:
keywords:
author: Danilo Mérida
license: (ISC) MIT
About to write to /Users/danimerida2000/Downloads/package-test/package.json:

{
  "name": "project-test",
  "version": "0.1.0",
  "description": "Project test",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Danilo Mérida",
  "license": "MIT"
}


Is this OK? (yes)
➜  package-test cat package.json
{
  "name": "project-test",
  "version": "0.1.0",
  "description": "Project test",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Danilo Mérida",
  "license": "MIT"
}

Si deseamos que asigne los valores predeterminados, usamos el flag -y (npm install -y)

Atributos que son generados en package.json:

  • name - nombre del paquete.

  • version - la versión actual del paquete.

  • description - descripción del paquete, y es usado para metanálisis en el registry.

  • main - el archivo de punto de entrada para iniciar el paquete.

  • scripts - shell scripts.

  • keywords - lista de palabras claves que mejora la visibilidad de un paquete publicado.

  • author - el paquete del autor.

  • licencia - la licencia del paquete.

Se puede ejecutar npm init después de la existencia del archivo package.json con el fin de actualizar cualquier atributo, inclusive es útil para leer un repositorio remoto de git y agregarlo a package.json.

PreviousPaquetes y dependenciasNextDependencias

Last updated 3 years ago

Was this helpful?