I published a package on NPM for the first time - and here's how to do it yourself! (Via replit.com)
Tags: npm, node, javascript
Published: 2022-02-01 00:22:14

> npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. ... Most commonly, it is used to publish, discover, install, and develop node programs.

Source: Google

### Step 1
* Create an account at NPM, and verify your email
* Then, create an account at https://replit.com, and click the * "Create" button at the the top left corner of the page !
* Select "NodeJS"
[Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hg5fz261973csir7boc.png)
 
### Step 2
* You should see something like this: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/735qg1q9sz0ihf85wkr8.png)
 
* Now, click on the "Shell button"
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4z5y8955zdvr1rkq2r.png)
  
* Run the following command: 
```
npm init
```
This will help you generate a `package.json` file. This will be useful later.

### Step 3 - Generating a package.json file
* Fill in the name: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9d8rut6ds1nlxhnwlbz.png)
* Fill in the version number: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/et91dxwbi9dtb3imt1uo.png)
* Fill in the description: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z72ibf3lz5ktbgzii9et.png)
* Fill in the entry point (The main file)   
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbbjcml839m4lcvynyvp.png)
* Fill in the test command, git repository, keywords, and author. These parameters are optional 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqb1d5t6n13f6d6rfwyd.png)
* Type "Yes" ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih4uoceuggo0k1xxhzdv.png)
* You should now see another file ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwsk5sw52qq9p6izvih8.png)

### Step 4 - Logging in to NPM
* Type `npm login` in the shell
* Enter your username and password
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cw2e0q3xa34p3cu7xgyq.png)
* Don't worry if you don't see anything when you type your password. This is for security purposes
* Type your email
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dx9j2ndsjl6txd5lroxg.png)
* You might have to verify your email
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rkjcgzf33r6fm0ufozth.png)


### Step 5 - Let's write some code!
Type the following your code in the `index.js` file
```js
// Taken from StackOverflow for demo purposes
function _genId(length) {
    var result           = '';
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result += characters.charAt(Math.floor(Math.random() * 
 charactersLength));
   }
   return result;
}
module.exports = _genId
```

### Step 6 - Let's publish our code
Run `npm publish` in the console
You should see something like this: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwbememebq3maeycockd.png)

Now, you can search your package on npm and install the npm package. Check out the `example.js` in the demo code

```js
const uuid = require("awesome-string-generator");
console.log(uuid(100))
```


## Demo
{% replit @ManuTheCoder/npm-package-test %}