🎆HOW TO CREATE YOUR OWN PACKAGE ON NPM EASILY, QUICKLY, AND UPDATED 2024🎆
Published: 2024-02-29 22:42:11

This post is also available, originally, in [Thread format on Twitter](https://twitter.com/Luciano655dev/status/1763330058389782898) and, in Portuguese, on [TabNews](https://www.tabnews.com.br/Luciano655/como-criar-seu-proprio-pacote-no-npm-facil-rapido-e-atualizado-2024).

![Image by Hare Prananda on LinkedIn](https://pbs.twimg.com/media/GHiJ-t2XQAAavp6?format=jpg&name=small)

# ⭐- WHAT ARE WE GOING TO DO?

In this thread, I will teach you how to create your **own package on NPM**, in an **EASY AND QUICK** way, with **JavaScript/TypeScript**!

This thread will be based on **my own package, BETTER-FORMAT**, which I will use as a reference!

[See more here on GitHub!](https://github.com/luciano655dev/better-format)

![Better-Format by Luciano655dev on GitHub](https://pbs.twimg.com/media/GHiK5T8WUAYQCgb?format=png&name=small)

# ✅- WHAT IS NPM?

NPM, or Node Package Manager, is simply a package manager for Node.JS.

In other words, it's a place where anyone can create and publish packages.

Here we have both HUGE and smaller packages, all useful for something!

![](https://pbs.twimg.com/media/GHiQ57ZXgAAe6nz?format=jpg&name=small)

# ✅- BEFORE CREATING...

Before creating an NPM package, think about what this package will do.

Better-Format, for example, helps you format and validate some types of data, such as strings, numbers, CPF validation, card, etc...

Just have an idea and put it into practice!

![](https://pbs.twimg.com/media/GHiRkK5W8AAuCyB?format=png&name=small)

# ✅- WHAT YOU WILL NEED

To create your first package, you just need an account on NPM and knowledge in some language, like JavaScript!

Depending on the package, you can also use other existing packages to help you, such as [axios](https://axios-http.com), [bcrypt](https://www.npmjs.com/package/bcrypt), etc...

![](https://pbs.twimg.com/media/GHiSjYjW8AAiR_I?format=jpg&name=small)

# ✅ 1 - HOW TO GET STARTED

First, you need to initialize a package, something you've surely done before, with `npm init`.

Fill in as much information as possible here, as it is important.

Before that, it's also good to create a repository on GitHub to link to your project!

![](https://pbs.twimg.com/media/GHiXOUEWsAAyhma?format=png&name=small)

# ✅ 2 - FIRST CODE

After initializing the package, create an `index.js` file and put something in it, like a `hello world`.

Then, run the `npm link` command, which will start your package locally, making it ready for testing.

![](https://pbs.twimg.com/media/GHiUs3XXUAAPPrm?format=png&name=small)

# ✅ 3 - CREATING THE PACKAGE

From here on, it's up to you and your creativity!

Create as many folders as you want, install as many dependencies as you want, and make your code work!

After that, just export everything in your `index.js` with `module.exports = {...}`!

![](https://pbs.twimg.com/media/GHiVfeQW8AAy6SH?format=jpg&name=small)

# ✅ 4 - CREATING TESTS

Along with everything you do, I strongly recommend running a test for it!

To do this, just install Jest with `npm i jest` and create a `./tests` folder, for example.

Here, you can test the functions you created! Use and abuse it!

![](https://pbs.twimg.com/media/GHiWPnEWEAELJl5?format=jpg&name=small)

# ✅ 5 - TESTING LOCALLY

Remember we ran the `npm link` command before? That's what allows us to test the package before it's published!

In another folder, run the command
`npm i {my_package}`

Then just import it with
`const myPackage = require('my_package')`

and test as much as you want!

![](https://pbs.twimg.com/media/GHiYZ3SXkAAFNyp?format=jpg&name=small)

# ✅ 6 - PUBLISHING THE PACKAGE

After developing the package, the simplest part is to publish!

Run the `npm login` command and enter your NPM account!

Then, check the version and run `npm publish` and YOU'RE DONE! YOU'VE ALREADY PUBLISHED YOUR FIRST PACKAGE!

To update, change the version and run the same command again!

![](https://pbs.twimg.com/media/GHiZJnaWQAA8cKo?format=jpg&name=small)

# ✅ 7 - AFTER PUBLISHING

After publishing, promote your package!

Post it on your social networks, everything! Besides, NPM itself distributes your package when you create it!

Remember to create a good README to attract people and make everything right on GitHub!

Check Issues, PRs, create a good environment for other developers, and hopefully, your package will be a success!

![](https://pbs.twimg.com/media/GHiZxeVXkAAVmyQ?format=png&name=small)

# ⭐ - BONUS

If you want to see more content about it, there are two videos that I HIGHLY recommend you to watch!

One from [WebDevSimplified](https://www.youtube.com/@WebDevSimplified) that shows in detail how to create the package.

And another from [Paula Santamaría](https://www.youtube.com/@PaulaSantamaria), which shows how she created her own package in a VERY well-produced video!

[WebDevSimplified video here](https://youtube.com/watch?v=J4b_T-qH3BY&t=233s)

[Paula Santamaría video here](https://youtube.com/watch?v=cdHb1fTl6_E&list=WL&index=1)

# 😄 - THANK YOU!

Hope you enjoyed it!

It had been a while since I last did a thread, mostly due to lack of good content, but I always want to post more!

If you liked it, visit the Better-Format repository! Your contribution will always be very welcome!

Thank you!