angeldlcm--npm--ch43
v1.0.0
Published
paquete para determinar si un numero es par o es impar
Downloads
7
Readme
Crear un nuevo paquete de npm desde cero.
Pasos para crear el proyecto
- Inicializar CLI en el directorio del proyecto y ejecutar el comando para inicializar npm
npm init
- Seguir las instrucciones de CLI: package name (nombre único), version, description, entry point (archivo js de entrada), test command, git repository, keywords, author, license.
- Podemos observar que se crea el archivo
package.json
con la información que proporcionamos. - Como definimos un entry point con el nombre
index.js
, hay que crear dicho archivo en main ya que aquí ejecutaremos nuestro package. - Crear una carpeta llamada
modules
en donde vivirá nuestro módulo (lógica de nuestro package) - Dentro de la carpeta modules, crear el archivo
parImpar.js
para desarrollar la logica del package. Aqui programamos la función que nos permite determinar si un número es par o es impar (código funcional de mi package). - Exportamos la función creada utilizando el comando
export default determinarParImpar;
- Importar mi función en
index.js
para poder utilizarla.
import function from route
Ejecutar el archivo index.js
9. Modificar package.json
para permitir la ejecución de modulos de EcmaScript (ES modules) agregando "type" : "module"
debajo de la clave-valor de "main": ""index.js