Publish a package to NPMJS.com directory 📦
Tags: npm, package, node, javascript
Published: 2021-09-25 10:40:33

Here are the easy simple steps to publish a new JS NPM package 😅

### 1. A [GitHub account](https://github.com/join) (optional; highly recommended) 🪄


The first step, it to have a GitHub account (you probably have one already). This is where you will store your code (in a repository) and where your README file and the git repo links will be synced with your npmjs.com package page.

### 2. An NPMJs.com account 🗝

You will need to create an account on [npmjs.com](https://www.npmjs.com/signup).



### 3. Version your package 📦

*Note: You can skip this section if you are releasing your very first version.*

Make sure your code is ready to be published. Make sure you correctly mention the files you don't want to be included thanks to `gitignore` or `.npmignore` (following the [.gitignore pattern rules](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring)).

Make sure your `package.json` file is properly formatted and contains all necessary information. 

![package-json-package-info](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6j0i9slhljg83ayd14m.png)
 

If so, you can commit everything with git and proceed to the release.

You can also add a `repository` section containing the GitHub link to your repo as show below:
```json
  "repository": {
    "type": "git",
    "url": "https://github.com/USERNAME/REPO_NAME.git"
  }
```



If so, let's create a stable version first thanks to `npm version [ major | minor | patch ]`

In my case, it will be `npm version major`, which will bump the version in your `package.json` to the major number (e.g., if your version was 1.0.0, it will now be 2.0.0).

The command will also create a new git tag.

### 4. Publish to NPM 🚀

In the terminal, type `npm login`

Login as the user name you previously created. Confirm your password and mention your email address you used when creating your npmjs.com account.

Then, in the root directory of your project, enter 
`npm publish`. 

![npm-publish-package](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uecynfqd1l617exkq1yh.png)
 

This will literally publish your package to the public NPMJS registry.


### 5. Let's check your package 🤗

Once that's done, go to https://www.npmjs.com/settings/{username}/packages

![npmjs-package-published-info](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mq9z6njxkrdslxlzss8g.png)

You should see your new package in there 🤗 The name of your package with be the same as the name you mentioned in your `package.json`, "name" field.


You will also receive an email from npm confirming that your package has been published.

![npm-email-package-published](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9ycspnnfk3vrtw6u4ga.png)
 
  
### Congrats! 🥳

Yaaay! 🎉 You are now all set! And your package is ready to be used by anyone 🚀


### Remove your package (or version) from NPM registry 🙈

In case you wish to delete your package from the public registry, you can run a `npm unpublish` through the terminal with the name of your package.


---

{% youtube YYIi-DOlEnI %}


—-

👉 Would you like to speed up your understanding on building real applications and APIs in JavaScript? My course covering API and frontend development is now available on Udemy: https://www.udemy.com/course/build-backend-api-node-js-and-react-frontend/