Introduction Node.js

9,627 views
9,154 views

Published on

Introduction to software development with Node.js

Published in: Software

Introduction Node.js

  1. 1. Introduction Node.js ERIK VAN APPELDOORN | MARCH 28TH 2014 | SDN EVENT
  2. 2. About me  Erik van Appeldoorn Trainer | Consultant  Avans Hogeschool, Academie Industrie & Informatica  Twitter: @evappeld  Blog: codeagainstthecode.tumblr.com  Mail: erixio@xs4all.nl
  3. 3. Subjects
  4. 4. JavaScript WHY?  Unstructured  Not intuitive  Unlogical  Prototypical Inheritance… WTF?  Dynamically typed  No Intellisense/code completion  Hard to debug  Global variables
  5. 5. 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
  6. 6. 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());
  7. 7. 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
  8. 8. Learn JavaScript!
  9. 9. JavaScript the good parts http://www.youtube.com/watch?v=hQVTIJBZook Dough Crockford
  10. 10. Learning JavaScript  http://www.codecademy.com/tracks/javascript  http://www.w3schools.com/js/default.asp  http://eloquentjavascript.net/  Learn Node.js
  11. 11. 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
  12. 12. 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/
  13. 13. 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
  14. 14. Node.js Event loop
  15. 15. 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
  16. 16. Hello Node.js World!
  17. 17. Hello Node.js World! + http server
  18. 18. http://nodejs.org/download/
  19. 19. Text editor  JetBrains WebStorm  Sublime Text  Visual Studio + Node.js tools for Visual Studio  Nodeclipse  Cloud9
  20. 20. Node Package Manager (NPM)  www.npmjs.org  60.000+ modules  package.json file (npm init)  npm install <module.name> --save  DEMO
  21. 21. Polular NPM modules express mocha restify jade socket.io redis underscore mongoose moment request async connect grunt passport
  22. 22. Local modules  DEMO
  23. 23. Node.js Website with express + jade
  24. 24. Node.js Website with express + jade  Express: http://expressjs.com/  Connect: http://www.senchalabs.org/connect/  Jade: http://jade-lang.com/  DEMO Connect
  25. 25. Features express: Routing
  26. 26. Features express: Views  DEMO Express + Jade
  27. 27. Node.js REST API with Restify
  28. 28. Restify  Maps HTTP verbs to CRUD operation  Handles URL & Body params  RESTIFY: http://mcavage.me/node-restify/
  29. 29. Restify  DEMO Restify
  30. 30. WebSockets
  31. 31. Node.js WebSockets with Socket.io
  32. 32. Socket.io  Bi-directional communication  WebSockets + fallbacks  SOCKET.IO: http://socket.io/
  33. 33. Socket.io  DEMO Socket.io Server Client
  34. 34. Node.js with Mongoose & MongoDB
  35. 35. MongoDB  NoSQL document store  JSON collections  MongoDB: http://www.mongodb.org/  Robomongo: http://robomongo.org/
  36. 36. Mongoose  Object modelling for MongoDB  Define schemas in Node.js for MongoDB  Query building (ODM)  Mongoose: http://mongoosejs.com/
  37. 37. Mongoose  DEMO Mongoose & MongoDB
  38. 38. The MEAN stack http://www.mean.io
  39. 39. QUESTIONS?

×