DEV Community

Thanh Tien Phat Nguyen
Thanh Tien Phat Nguyen

Posted on

Publish your first package on npm!

Introduction

This week we are asked to release our work by choosing a release method. To make our work, I decided to release my very first package on NPM. You can also check it out at here.

Why NPM?

There are several reasons why I decided to choose NPM as my release method. Firstly, NPM is super popular to the developers all around the world. Therefore, publishing my package on the site would be a good idea. Moreover, since all of the dependencies used in my projects are published on NPM, it gives me a solid reason to go with NPM

How?

To publish my first ever package on NPM, these are the steps that I took at the time:

npm login
Enter fullscreen mode Exit fullscreen mode
  • Next, create a package.json file in your folder.
npm init
Enter fullscreen mode Exit fullscreen mode

You can change the name and the version of your package inside your package.json file. Below is what I did in my file:

{
  "name": "link-checker-tool",
  "version": "1.0.2",
  "description": "A tool used to check whether an URL is available or not",
  "bin": {
    "lct": "/link-checker.js"
  },
  "keywords": [
    "cli"
  ],
  "scripts": {
    ...
  },
  "preferGlobal": true,
  "author": "Thanh Tien Phat Nguyen",
  "license": "ISC",
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode
  • To make it easy for other people understand how to use your package, update your README.md document which allows users to have some basic knowledge about your package. Below is a piece of my README.md, you can check the full version at here.

Alt Text

  • Lastly, publish your package by using this command:
npm publish
Enter fullscreen mode Exit fullscreen mode

If you get the message below, your package is published successfully.
Alt Text

How to use my package?

My package this is an CLI that checks if a url is available. Some of the features that I have added to this package is:

  • Check and print all the good, bad and unknown links in a file.
  • Read multiple files at once.
  • Check the availability of an URL.
  • Give the URL to an archived version of a website.
  • Output JSON format of a URL entered.

To install my package, please use the command

npm install link-checker-tool

Enter fullscreen mode Exit fullscreen mode
npm install -g link-checker-tool

Enter fullscreen mode Exit fullscreen mode

For more usages of my package, you can read my whole document for more information.

What I learn from this week lab

  • How to release a package
  • How to improve the workflow by tagging my release.

Top comments (0)