This repo demonstrates on how we can create sample npm package and publishing to npm registry
- Create the project directory ( mkdir sample-directory )
- Change into the project directory (cd sample-directory )
- Initialise a new NPM package ( npm init ) Empty package json will be created
- Update package.json and project code (index.js)
(You should have account created in npm registry if not you can create new account (https://www.npmjs.com/signup)
- Open command prompt then enter npm login command and provide the login credentials
-
run npm whoami to confirm
-
Then run npm publish
- Your new package will be published to your npm registry like mine :) https://www.npmjs.com/package/random-number-generator-santhosh-sample-package
-
Open NPM RunKit (https://npm.runkit.com/random-number-generator-santhosh-sample-package)
-
Invoke the method we created using below piece of code and click on run button
var randomNumberGeneratorSanthoshSamplePackage = require("random-number-generator-santhosh-sample-package")
console.log(randomNumberGeneratorSanthoshSamplePackage(10,5))
- I created this package to generate the random number and print it on console.
- Make changes in your package then run npm version patch command
- Publish it to npm registry using npm publish command
Happy Coding!!