uno--cohorte43
v1.0.0
Published
el primero de muchos
Downloads
7
Readme
Crear un nuevo paquete de npm desde cero
pasos para crear el proyecto
- Inicializar el 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 (1.0.0), descripción, entry point (archivo js de entrada), test command, git repository, keywords, autor, Licence,
Se creo el archivo .json con la información
como definimos un entri point como index.js, hay que crear dicho archivo en main ya que aquí ejecutaremos nuestros package
crear una carpeta llamada 'modules' en donde vive nuestro modulo(logica de nuestro packaeg)
dentro de la carpeta modules crear el archivo 'parImpar.js' para desarrollar la logica del package.
Aquí programamos la función que nos permite determinar si un número es par o impar (código funcional de mi package)
- Exportamos la función creada utilizando las palabras reservadas 'export defaul ...'
ejemplo
export default determinarParImpar;
- Importamos la función creada utilizando las palabras reservadas 'import ...'
ejemplo
import determinarParImpar;
- Modificar
package.json
parapermitir la ejecución de módulos de ES Script (EcmaScrip) agregando '"type":"module"' debajo de la clabe valor de "main":"javascript" Ejecutar el archivoindex.js
con el comando
node index.js
Pasos para publicar un package en npm
- Estar registrado
- Ejecutar el comando de inicio de sesión de npm
npm login
- publicar nuestro package con visibilidad pública en npm utilizando CLI
npm publish --access=public