It's all about Node.js


@giftkugel

Simon Skoczylas Senior Software Developer
Materna GmbH

Java, JavaScript
Web, Frontend

Agenda

  1. Motivation
  2. Node.js Facts & History
  3. Documentation
  4. Installation and Configuration
  5. Tools/Frameworks

Motivation

Motivation

  • Why should i use Node.js? Hype?
  • JavaScript Development is Web Development
  • Client and Server-side / Front-end and Back-end

MotivationLanguage Trends on GitHub (August 2015)

MotivationTIOBE Index (August 2016)

MotivationTIOBE Hall of Fame 2015

MotivationThe Dawn Of Enterprise JavaScript

JavaScript Finds Its Place In Enterprise Software Development

Adoption of JavaScript — and the Node.js runtime environment in particular — sets the stage for the biggest shift in enterprise application development in more than a decade

Node.js Facts & History

Node.js Facts & HistoryHistory Part 1

Node.js Facts & HistoryHistory Part 2

Node.js Facts & HistoryArchitecture of Node.js

Node.js Facts & HistoryFacts

  • Server-side JavaScript
  • V8 Engine by Google, written in C
  • Non-blocking I/O
    • JavaScript Event-Loop
  • Event-driven
  • Single-Thread (actually)
  • Linux, MacOS, Windows, SunOS, ARM
    • 32bit & 64bit
    • ARM6, ARM7, ARM8

Node.js Facts & HistoryNPM

  • Node Package Manager
  • Since 2011
  • ~183.000 Modules at npmjs.com
  • package.json describes the project
  • Fetches dependencies described in package.json
  • Compiles native addons for the platform
  • Consider private NPM repositories!
  • NPM 3.3.6 (since Node.js 5.0.0 with better Dependency Resolution)

Documentation

DocumentationAPI

DocumentationDefault modules

  • Assert (like JUnit)
  • Addons (C/C++)
  • Buffer
  • Child Process
  • Cluster
  • Console
  • Crypto
  • Debugger (Remote)
  • DNS
  • Errors
  • Events
  • File System
  • HTTP / HTTPS
  • Modules
  • net
  • OS
  • Path
  • process
  • punycode (Encode, Decode)
  • Query String
  • Readline
  • Stream
  • StringDecoder
  • Timers (setTimeout, etc.)
  • TLS (SSL)
  • UDP / Datagram Sockets
  • URL
  • util
  • VM
  • Zlib

Installation and Configuration

Installation and ConfigurationInstallation

  • Linux: Install with your favorite Linux Package Manager (YUM, APT etc.)
    • Packages often out of date! YUM EPL will install Node.js 0.10.x
  • Download from nodejs.org
  • Use NVM before installing Node.js/NPM (Node Version Manager)
  • Get the official Docker image

Installation and ConfigurationConfiguration

  • npm config
  • npm config get [<key>]
  • npm config set <key> <value>
  • npm config edit (Open Sesame!)
  • npm -g for global configuration

Installation and ConfigurationMy Windows configuration (Shame on me!)

D:\node-slides>npm config list

; cli configs
user-agent = "npm/2.15.8 node/v4.4.7 win32 x64"

; userconfig C:\Users\sskoczyl\.npmrc
msvs_version = "2015"
proxy = "http://proxy.materna.de:8080/"
python = "python2.7"

; globalconfig C:\Users\sskoczyl\AppData\Roaming\npm\etc\npmrc

; builtin config undefined
prefix = "C:\\Users\\sskoczyl\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = D:\node-slides
; HOME = C:\Users\sskoczyl
; 'npm config ls -l' to show all defaults.
Bad prefix!
npm config get prefix
C:\Users\sskoczyl\AppData\Roaming\npm
Better prefix! (add to PATH)
Linux:
npm config set prefix $HOME/.node_modules_global
Windows:
npm config set prefix %userprofile%\node_modules_global

Installation and ConfigurationProject Setup

D:\node-slides>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (my-first-cool-project)
version: (1.0.0)
description: This is my first very cool project
entry point: (index.js)
test command: grunt nodeunit
git repository: https://git.myfirstcoolproject.com
keywords: cool
author: Me (me@myfirstcoolproject.com)
license: (ISC)

Installation and ConfigurationProject Setup

  • package.json for this slides
{
"name": "reveal.js",
"version": "3.3.0",
"description": "The HTML Presentation Framework",
"homepage": "http://lab.hakim.se/reveal-js",
"subdomain": "revealjs",
"main": "js/reveal.js",
"scripts": {
"test": "grunt test",
"start": "grunt serve"
},
"author": {
"name": "Hakim El Hattab",
"email": "hakim.elhattab@gmail.com",
"web": "http://hakim.se"
},
"repository": {
"type": "git",
"url": "git://github.com/hakimel/reveal.js.git"
},
"engines": {
"node": "~4.1.1"
},
"dependencies": {
"express": "~4.13.3",
"grunt-cli": "~0.1.13",
"mustache": "~2.2.1",
"socket.io": "~1.3.7"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-autoprefixer": "~3.0.3",
"grunt-contrib-connect": "~0.11.2",
"grunt-contrib-cssmin": "~0.14.0",
"grunt-contrib-jshint": "~0.11.3",
"grunt-contrib-qunit": "~0.7.0",
"grunt-contrib-uglify": "~0.9.2",
"grunt-contrib-watch": "~0.6.1",
"grunt-sass": "~1.1.0-beta",
"grunt-zip": "~0.17.1",
"node-sass": "~3.3.3"
},
"license": "MIT"
}

Installation and ConfigurationProject Setup

npm install foobar --save --save-exact
npm config set save=true
npm config set save-exact=true
npm start

Tools/Frameworks

Tools/FrameworksIDE

Tools/FrameworksBuild-Tools, Choosing a JavaScript Build Tool


It's not an either-or proposition.
Mimosa - a build tool for modern web development

Tools/FrameworksTests

  • Mocha
    • Mocha is a feature-rich JavaScript test framework
  • Jasmine
    • Jasmine is a Behavior Driven Development testing framework for JavaScript
  • UnitJS
    • Unit.js is an assertion library for Javascript, running on Node.js and the browser
  • Chai
    • Chai is a BDD / TDD assertion library for node and the browser
      that can be delightfully paired with any javascript testing framework
  • ESLint
    • The pluggable linting utility for JavaScript and JSX

Makeing the unit tests pass! ;-)

Tools/FrameworksWeb-Frameworks

  • Express
    • Fast, unopinionated, minimalist web framework for Node.js
  • hapi
    • A rich framework for building applications and services
  • Restify
    • Restify is a node.js module built specifically to enable you to build correct REST web services
  • Koa
    • Next generation Web Framework for Node.js

Tools/FrameworksOther

  • Yeoman
    • Scaffolding Tool » Generators
  • Slush
    • The streaming scaffolding system
  • Bower
    • A package manager for the web
  • JSPM
    • Frictionless browser package management

Tools/FrameworksPackages people 'npm install' a lot

My favorite tutorials

Questions?

// http://kangax.github.io/compat-table/es6/ // Verwendbar über Featuredetection und Polyfills