DEV Community

Cover image for NPM Package
DerekJxy
DerekJxy

Posted on

NPM Package

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.
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. 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
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
This time, I prefer to find the solution from the Internet. Then, I just googled this situation from Stack Overflow. 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 to test my package. Fortunately, this time I didn't any errors. I can test my package smoothly.
test

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

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]

Top comments (0)