Publish your first npm library! Become an open source contributor (to increase your salary)
I call myself ‘Salary Hacker’. Because I know the secret to increasing my salary quickly. One of them is to be an open source contributor.
Publish a library with your name, you will be acknowledged quickly.
The usefulness of the library is not very important. Just by distributing a library, you are already in the top 20% of a developer. (80% didn’t)
If you are a rookie developer, interviewer would say
“Look, this newbie at least tried to contribute to the open source! Impressive.” Believe me. That was the case for me.
So today, I am going to introduce how to distribute npm library, which is one of the easiest package distribution system.
If you want to publish npm with typescript, check this!
Introducing My Libraries
You want to do the same? Here we go!
[1] Register Your Account
Do I have to explain this?
[2] Prepare your git repository
[3] Create your project and initialize git
(1) Create directory
# create directory
mkdir my-first-cool-library
# change directory
cd ./my-first-cool-library
(2) initialize git
git init
git remote add origin https://github.com/paigeshin/my-first-cool-npm-library.git
Note that https://github.com/paigeshin/my-first-cool-npm-library.git, this should your own repository address.
[4] Initialize npm inside your project
# initialize npm
npm init
Now, you will be asked multiple questions. Just fill out anything for now. You can change it later in package.json
.
[5] Write your code
- index.js
function add(a, b) {
return a + b;
}module.exports = add
Now, we created simple add
function.
All sources from index.js
will be exported. You can change this on package.json.
[6] Publish your first library!
# login from sheel
npm login
# publish your library
npm publish
This is it!
Conclusion
- Create git repository
- Initialize project with npm
- Write Code
- Publish it!
I intentionally skipped .gitignore and .npmignore. This is just the most basic tutorial without causing headaches! So I tried to explain it as briefly as possible.