Publicar un paquete de npm tutorial

Ver Otros Cursos

Este es un ejemplo practico de Nodejs y Javascript, en el que aprenderemos a publicar un modulo de Node en npmjs.com, el registro de repositorio de código de Node.

455 vistas

similar to: nodemon express-generator create-react-app etc

mkdir npm-helloworld npm init -y

un src/index.js

const axios = require('axios');

const greet = name => 'Hello ' + name;

const users = async () => {
  const res = await axios.get('https://jsonplaceholder.typicode.com/posts?_limit=2')
  return res.data;
}

users()

module.exports = {
  users,
  greet
}

you need an npm account. to add one: npm adduser

then you can go to npm and login.

npm whoami

if you have an account npm login

to see the version of our package npm version

to update the version

make sure the name of your module is unique, because it could be other packages with the smae name. so for this example i will add in package.json in the name something like: npm-helloworld-fazttest.

then: npm publish

you can go yo your npm profile and see the package sin un README.md

Let's add a readme.

create a README.md

# example npm package
* getUsers
* greet

npm version 1.0.2 npm publish

using your module

const {greet, users} = require('npm-helloworld-fazttest')

console.log(greet('Fazt'));

users().then(data => console.log(data))

github

upload to githb npm init -y npm version 1-0.3 npm publish