Let's Create & Publish Our Own NPM Package!

Let's Create & Publish Our Own NPM Package!

A beginner's tutorial for building npm package as well as publishing it!

ยท

2 min read

Table of contents

No heading

No headings in the article.

Requirements

  • NodeJs installed on your machine
  • A registered NPM account (if not, sign up here ๐Ÿ‘‰ npmjs.com/signup)

Let's get started

Step 1 : Initiating package.json We will be building a simple package, which will provide a functionality to convert a normal string into camelCase string.

Example, 'this is normal string' will be converted to 'thisIsNormalString'.

Create project directory - mkdir camel-it

Navigate to the directory - cd camel-it

Open this directory in a code editor.(I'll be using VSCode)

Open the terminal & run npm init command.

It'll present you with questions like

  • package name (make sure you provide a unique package-name)
  • version (keep it as it is i.e. 1.0.0)
  • description: A short info about the package
  • entry point (index.js): This prompt is important one, since it indicate the entry point of our package. We will create a file index.js later.
  • test Command as of now, we are not going to write tests, so this promp can be blank
  • git repository : as of now, we are not initiating github repo, so this can be updated later.
  • keywords : These are words relevant to your package, that helps the package to get visibility in search results
  • author: You can put your name here
  • license: This is the place where you'll mention the license, as of now, we are leaving it blank
  • After this, command line will show us a preview of previous question-answers, if everything is okay, type y in terminal - This will create a package.json file.
ย