NPM Package
Tags: opensource, github, npm, javascript
Published: 2021-11-26 23:58:15

This week, we are going to have out __Lab 10__ in `OSD600`. Lab 10 is quite __different__ from any other previous lab I had in OSD600. Lab 10 is not about coding or adding new feature to my static site generator. It's about __publishing__ my SSG to [__npm__](https://www.npmjs.com/). 
Once I published my SSG to the __npm__, people would be able to use my SSG as long as they install my package by the command: `npm i my-first-ssg-1`.

###Procedure
After reading the __Lab 10__ _instruction_ as usual, I just started to read the documentation about the [npm](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry). Because I have my SSG in a good set, I don't need to create or modify that much things when I followed the steps from the documentation. 

And then, I just tried to __publish__ my SSG. __However__, because this is the first time I work on publishing package to __npm__. I have not idea how it works. 
__Therefore__, I just run the command `npm publish` directly, which comes up with my first error:
![error1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovn72wvgrtdkezlnouhy.png)
So I just ask my friend what am I supposed to do in this situation. And then my friend replied me, __"Did you login your npm accont?"__ And at that time, I just realized that __I don't even have a npm account__. 
So, I just use the link my friend sent me to sign up a __npm__ account. And tried to publish it again.

__However__, after run the command 'npm publish'. There was a new error comes up: 
![error2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw0ysivo9fwvu6yzuntk.png)
This time, I prefer to find the solution from the Internet. Then, I just _googled_ this situation from [Stack Overflow](https://stackoverflow.com/). And I found that, the reason for the error above was __I didn't verify my npm account__. So I verified my __npm__ account through the __e-mail__ they sent me. And finally, I can publish my SSG to __npm__ __successfully__. 

After my SSG package published to __npm__. I followed these [steps](https://docs.npmjs.com/creating-node-js-modules) to test my package. Fortunately, this time I didn't any errors. I can test my package smoothly.
![test](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14v0n1jszr9hbzjr6vwp.png)

Finally, I realized that I need to __update__ my `README.MD` for the __npm__ package. I thought I can delete the package and then remake it. But the reality is, I need to wait for __24 hours__ after I __deleted__ the package. __Therefore__, instead of using the same name as my SSG program name "__my-first-ssg__", I need to create a new package with a different name for my package "__my-first-ssg-1__". 
After I recreate a __npm__ package, I just __update__ the content in my `README.MD` file and then used the command: `npm publish` to make updates to the package I had in __npm__.
![update](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7ynrfe03cv08h0juedl.png)

###My Feelings
I would say this is a __simple__ and __tricky__ lab. The simple aspect is I don't need to code anything for this lab. But the tricky aspect is there is __no any example__ as a reference to accomplish this lab. And that is the reason I suffered some stupid errors. __However__, I think this is a correct way to learn stuff, because we won't have that much example when I work in a company. I think this is a good practice for us to ready for solve problems in the workplace in the future. __Also__, I think lab 10 is very useful. I learned that we can use __npm__ package to publish our code so that other people can use it by running 1 simple command `npm i packagename`. And they don't need to clone my code and build my project to run it locally. 
It's a very convenience way to allow people to use my package!

Link to my __npm__ package: [[my-first-ssg-1](https://www.npmjs.com/package/my-first-ssg-1)]