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!

[1] Register Your Account

Register your account

Do I have to explain this?

[2] Prepare your git repository

Create your 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.

Termnial

[5] Write your code

  • index.js
function add(a, b) {
return a + b;
}
module.exports = add

Now, we created simple add function.

Do you want to change root source?! Do it here

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

  1. Create git repository
  2. Initialize project with npm
  3. Write Code
  4. 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.

--

--

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!