Publish your first NPM Package
NPM pacakge

Publish your first NPM Package

This article provides a comprehensive, step-by-step guide for technical enthusiasts to create and publish their inaugural NPM package.

Requirement to proceed:

  • Installation of Node
  • Basic Knowledge of JavaScript
  • Code Editor (Visual Studio or VS Codium)
  • Basic knowledge Linux Command line

Step 1: Create a Directory

mkdir <filename> # Command to create a directory
cd <filename> # Change directory         

Step 2: Initialize NPM in the directory

npm init        

This contains the metadata about your package. Here my package name is "publishfirstpackage" and remaining configuration is set to default

Step 3: Build your first function

Let us now build a function in our package. First create a index.js in package to proceed with writing your code.

function createpattern() {
    // Set the size of the pattern
    const size = 5;

    // Loop to create the pattern
    for (let i = 1; i <= size; i++) {
        let row = '';
        for (let j = 1; j <= size; j++) {
            row += '* ';
        }
        console.log(row);
    }
}

module.exports = createpattern        

You should export your function as shown in the previous example after developing it. Anyone who gets your package will be able to utilize it in their code as a result.

Step 4: Publishing our First Package

You must register for an account in order to publish your package on the NPM registry. Go to the NPM sign up page to establish an account if you don't already have one

After successfully creating your account, go to your terminal and run the following npm command

npm login        

You will be getting the above prompt, that means you have successfully logged in.

We can now publish our package by the following npm command

npm publish        

Congratulations, you successfully publish your first package into the NPM registry

If you want your check your package in the NPM website. Navigate to the NPM official website and go to your profile.

In your profile page, you can see your list of packages that published and available to the user.

Conclusion

Packages enable quicker development. Creating and publishing your solution as a package is one method by which?you may share a better way of doing things with the community.

You discovered what packages are and their benefits in this article. Additionally, you learned?how to build and post packages to the NPM registry. The developer community is eager to see all the lovely packages you produce and share.

Thank you for reading.


G Madhu Sudhan Rao

Software Engineer 1 @ Astreya (Data) | Reading about Database Internals ?? | Prev: SDE Intern @ Siemens DISW

1 年

Never thought publishing an npm package was just a 2 step process??

要查看或添加评论,请登录

Tanmay Pradhan的更多文章

  • NPM for Beginners

    NPM for Beginners

    What is NPM? npm stands for Node Package Manager. It is the default package manager for Node.

    2 条评论
  • BEST YT CHANNELS FOR MACHINE LEARNING.

    BEST YT CHANNELS FOR MACHINE LEARNING.

    Sentdex Tech with Timm Freecode camp Khan Academy 3Blue1Brown Edureka Machine learning resources Machine Learning…

社区洞察

其他会员也浏览了