Introduction Node.js
ERIK VAN APPELDOORN | MARCH 28TH 2014 | SDN EVENT
About me
 Erik van Appeldoorn Trainer | Consultant
 Avans Hogeschool, Academie Industrie & Informatica
 Twitter: @evappeld
 Blog: codeagainstthecode.tumblr.com
 Mail: erixio@xs4all.nl
Subjects
JavaScript WHY?
 Unstructured
 Not intuitive
 Unlogical
 Prototypical Inheritance… WTF?
 Dynamically typed
 No Intellisense/code completion
 Hard to debug
 Global variables
JavaScript is strange (I)
console.log(1 == true); //true
console.log(1 === true); //false
console.log("0" == false); //true
console.log("abc" == "a" + "b" + "c"); //true
console.log(null == undefined); //true
console.log(30 -"7"); //23
console.log("30" + 7); // 307
JavaScript is strange (II)
function rectangle(x,y) {
this.x = x;
this.y = y;
}
rectangle.prototype.area = function() {
return this.x * this.y;
}
var twoByThree = new rectangle(2,3);
console.log(twoByThree.area());
But…JavaScript is relevant
 THE language of the WEB
 Cross-platform
 Huge REACH
 JavaScript is everywhere (client, server, libs, frameworks)
 Single Page Applications
 Server applications
 End-to-End JavaScript applications
Learn JavaScript!
JavaScript the good parts
http://www.youtube.com/watch?v=hQVTIJBZook
Dough Crockford
Learning JavaScript
 http://www.codecademy.com/tracks/javascript
 http://www.w3schools.com/js/default.asp
 http://eloquentjavascript.net/
 Learn Node.js
What is Node.js?
 Open Source, Cross platform Development platform
 Uses V8 JavaScript engine (Google)
 “JavaScript on the server”
 Node.js is a command line tool
Node.js history
 Developed in 2009
 Published in 2011 (Linux only)
 Ryan Dahl, Joyent
 From July 2011 Windows version available
 Active community: check http://nodeconf.com/
Node.js architecture
 Node.js is event-driven with Non-blocking I/O
 Uses a Event loop for Non-blocking I/O
 Node.js is single threaded
Node.js Event loop
Node.js applications
“Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network
applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time applications that run across distributed devices.”
 HTTP server
 REST server
 Web Sockets
 TCP server
 Utillities
Building Scalable Network programs
Hello Node.js World!
Hello Node.js World!
+ http server
http://nodejs.org/download/
Text editor
 JetBrains WebStorm
 Sublime Text
 Visual Studio + Node.js tools for Visual Studio
 Nodeclipse
 Cloud9
Node Package Manager (NPM)
 www.npmjs.org
 60.000+ modules
 package.json file (npm init)
 npm install <module.name> --save
 DEMO
Polular NPM modules
express mocha
restify jade
socket.io redis
underscore mongoose
moment request
async connect
grunt passport
Local modules
 DEMO
Node.js Website with express + jade
Node.js Website with express + jade
 Express: http://expressjs.com/
 Connect: http://www.senchalabs.org/connect/
 Jade: http://jade-lang.com/
 DEMO Connect
Features express: Routing
Features express: Views
 DEMO Express + Jade
Node.js REST API with Restify
Restify
 Maps HTTP verbs to CRUD operation
 Handles URL & Body params
 RESTIFY: http://mcavage.me/node-restify/
Restify
 DEMO Restify
WebSockets
Node.js WebSockets with Socket.io
Socket.io
 Bi-directional communication
 WebSockets + fallbacks
 SOCKET.IO: http://socket.io/
Socket.io
 DEMO Socket.io
Server
Client
Node.js with Mongoose & MongoDB
MongoDB
 NoSQL document store
 JSON collections
 MongoDB: http://www.mongodb.org/
 Robomongo: http://robomongo.org/
Mongoose
 Object modelling for MongoDB
 Define schemas in Node.js for MongoDB
 Query building (ODM)
 Mongoose: http://mongoosejs.com/
Mongoose
 DEMO Mongoose & MongoDB
The MEAN stack
http://www.mean.io
QUESTIONS?

Introduction Node.js