JS Ecosystem

TotT: 2014

JS Server Side (NodeJS)

  • Has module definitions, imports
  • Has a slim standard library
  • Has encouraged development and sharing of small tools

Example: exports, require

In foo.js

module.exports.double = function(x) {
  return x * 2;
};

var triple = function(x) {
  return x * 3;
};

In bar.js

var foo = require('./foo');
var z = foo.double(5);
console.log(z);
var q = foo.triple(5) // ERROR!

Node Packaged Modules

  • A method of distributing NodeJS modules
  • A hosted index of published modules
  • A command line tool for managing modules

npm

Commands to master:

$ npm search
$ npm install [-g]
$ npm init

Demo: NPM Basics

search, install, require

Demo: NPM Basics

package.json

  • Package metadata
  • States name, author, version, git repo, ...
  • Critically, lists dependencies

Example: package.json

{
  "name": "totter",
  "version": "0.0.1",
  "description": "Demonstration module for TotT",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  },
  "repository": {
    "type": "git",
    "url": "git@bitbucket.org:unctott/totter.git"
  },
  "keywords": [
    "teaching",
    "tott",
    "unc"
  ],
  "author": "Peter Parente",
  "license": "BSD",
  "dependencies": {
    "jade": "~0.27.6",
    "markdown": "~0.4.0"
  }
}

Demo: package.json Pizzazz

npm, package.json, colors

Demo: package.json Pizzazz

JS Client Side (Browsers)

  • Long ago: Snippets to add a tad of interactivity
  • Then: Libs to hide cross-browser scripting issues
  • Now: Libs to support rich Web app development

To Be Continued

In sessions about frontend JS

Review

  • NodeJS
  • NodeJS Modules
  • NodeJS Packaged Modules
  • npm
  • package.json