Npm publish

Publishing on npm repository

Writing your own custom modules and then publishing them on npm.

The example here deals with publishing a module on npm and then using it. Here amitcalcapp is published on npm repository and then we are using it in our app.

package.json example:

Created using `npm init`, and then installed the 'amitcalcapp' module from npm repository using the command 'npm i amitcalcapp --save'

{
  "name": "example3",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "amitcalcapp": "^1.0.3"
  }
}
Application's main file (index.js)

In `package.json`, you can see we have downloaded this package from npm repository.

var calc = require('amitcalcapp');

var a = 10;
var b = 20;

var c = calc.add(a, b);
console.log('add: ', c);