Nibbles and Bits

A Little Insight Into Node Modules, Packages, and package.json

node.js

Node packages consists of modules, which are basically JavaScript files.  They are usually written to be as minimalist as possible.  In order to use another Node module in your file, you need to import it using the require keyword.   It is customary in node to name the variable the same as the module.

var fs = require('fs');
When wanting to export your own module, you can wrap any JavaScript object (object, function, variable, etc.) and assign it to module.exports.
module.exports = my_module_object;
Every Node package consists of at least one module and package.json file.  Thepackage.json file acts as the manifest and provides metadata about the package and lists any dependencies.  Many of these dependencies will live in a folder in the package called node_modules.  Inside this folder will be other packages that contain other packages, each having their own node_modules folder and package.json file.  The only required entries for a package.json file is the name and version details.  Other values are explained on the npm website[https://docs.npmjs.com/files/package.json].  In the dependency sections for a package.json, you will see the names and version numbers for different packages.  Some of the version numbers may be prefixed with a ~ or a ^.   The meanings of these are interpreted by semantic versioner [semvar] package of npm.  The meanings and rule set for versions are explained here:
https://docs.npmjs.com/misc/semver
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.2",
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "es6-shim": "0.35.1",
    "express": "~4.13.1",
    "hbs": "~3.1.0",
    "morgan": "~1.6.1",
    "pg": "^6.0.3",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "serve-favicon": "~2.3.0",
    "systemjs": "0.19.26",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.10",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "3.11.0",
    "typescript": "1.8.10",
    "typings": "1.3.1",
    "del": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.13.6",
    "systemjs-builder": "^0.15.19"
  }