Hello Guys I am Shiro and Today I'm going to tell you how to write and publish your first NPM package..!
Prerequisites
- NodeJS & NPM
- account on npmjs.com
- Visual Studio Code
Login to NPM
$ npm login
Fill these details and login.
Use this command to know if you have successfully logged in.
$ npm whoami
If you can see your username you have successfully logged in
Create your NPM package
First create a new folder to hold your package. then open that folder in terminal and use this command.
$ npm init -y
Write your code
Then open the folder in vscode and create a file called index.js. In here I am going to show you how to write a simple package to multiply two numbers.
You can copy and paste this code into index.js
Publish package
You can use this command to publish your first NPM package
$ npm publish
If there is no error you can goto your Profile in NPM and see your first NPM package.
Install your package
You can install your package and test it by using this command
$ npm install <package name>
Congratulation..! ๐ You have successfully published your first NPM package :)
If you have any problem comment below
Happy Coding ๐
Top comments (0)