Node js introduction


Published on

Introduction to node.js (Node) and how to install node on a pre-built Ubuntu Virtual appliance.

Published in: Technology

Node js introduction

  1. 1. NodeJS Introduction<br />What is Node? (Teaser)<br />How to install/set-up and examples<br />
  2. 2. Introduction<br />Introduction to Node JS<br />How to Install/Tools<br />Basic Node concepts (teaser)<br />Demo<br />
  3. 3. Nodejs Introduction<br />NodeJS is built on Google’s V8 Javascript engine<br />Server-side non blocking asynchronous JS<br />Perfect for “blood” of Web 2.0 apps (streams, comet, AJAX, etc) and scale<br />
  4. 4. How to Install (VM) (1/5)<br />Download Ubuntu TurnKey from<br />Download the free Vmware player from<br /> (or use VMWare Workstation)<br />Start the Turnkey Virtual Appliance and follow instruction to set-up root password and update security.<br />Note IP@ to connect to with SSH<br />
  5. 5. How to Install (SSH) (2/5)<br />Get your favorite SSH tool (duh, Putty!)<br /><br />Set-up your SSH connection as indicated left <br />Approve to the RSA key as shown right <br />
  6. 6. How to Install (Misc.) (3/5)<br />Get Filezilla if you want to transfer through SSH with your favorite editor<br />I use NotePad++ an NppFTP extension (not automated but easier to remember)<br />
  7. 7. How to Install (Git) (4/5)<br />Install Compile tools<br />apt-get install gcc<br />apt-get install g++<br />apt-get install make<br />Install Git (would be a good L&L. Volunteers?)<br />apt-get install git-core<br />Git the node repo: <br />(alternative is to download & install the TAR’ed version from nodejs but what’s the fun  ?<br />wget<br />gitclone git:// <br />Make sure to use the latest stable version<br />(As of 10/3/2011, I recommend 0.4.11. 0.4.12 seems to be the latest though)<br /> cd node<br />gitcheckout v0.4.11 <br />Configure/Make<br />./configure<br />Make<br />Make Install<br />You are all set:<br />cd benchmark/<br />node v8_bench.js<br />
  8. 8. How to Install (NPM) (5/5)<br />Get CURL<br /> apt-get install curl<br />Install NPM<br />curl | sh<br />You are all set<br />npm<br />
  9. 9. What is NPM?<br />NPM is a Node Dependency manager (better than APT)<br />Get a package, and all dependent package will automatically be installed<br />
  10. 10. Good Node Packages<br />Connect<br />The middleware framework for node: Logging, Cookies, Sessions, Cache, response time …<br />Express<br />Built on Connect. Essentially all the libraries that people are used to when doing server side development (such (Routing, content negotiations, configurations, etc) <br /><br />“Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.” (essentially synthetically do “sockets” in HTTP)<br />Twitternode<br />A complete node twitter client API wrapper supporting full JSON streams.<br />
  11. 11. Why on earth would I want do do server-side JavaScript?<br />Because geeks like to play with new things<br />Because you like the open/flexible/powerful nature of a language such as javascript<br />You already do a lot of client-side javascript<br />You need to “Web” scale<br /><ul><li>You need to communicate with many other resources
  12. 12. You do many medium size payloads that could benefit from asynchronous processing
  13. 13. Many javascript developers and a growing established open-source javascriptlibraries and code repository</li></li></ul><li>More importantly :<br />It’s cool: <br /><ul><li>And, it hasn’t jumped the shark (yet?):</li></li></ul><li>Give me the geek version<br />Performance rocks on many connections, resources utilization<br />No concepts of threads, which is an extremely wasteful idea when trying to server many (thousands) requests<br />Streaming (comets) & big data payloads (big .csv reports scaled to thousands) do not scale on thread-based servers<br />Non blocking calls can handle way more requests/seconds and use less memory<br />Source:<br />
  14. 14. So what have we learnt so far?<br />Node.JS is using non-blocking, event-based (asynchronous) engine to deliver a much more scalable server<br />Javascript is a really natural fit for event-based programming<br />
  15. 15. Events in Node.js<br />Relies on event-loop system<br />Should be familiar for all developers (.net …) who used events & delegates or others who are familiar with concept of callbacks.<br />Javascript is a really natural fit for event-based programming<br />Builds on anonymous functions (lamba*) <br />* Tom will do a L&L on advanced JS (closure, Lambda) concepts shortly<br />
  16. 16. Blocking vs Non Blocking<br />
  17. 17. Event Loop Demo<br />Demo!<br />
  18. 18. NodeJS Full Demo<br />
  19. 19. References<br />Web faction blog<br /><br />Understanding event loops and writing great code for node.js<br /><br />A Not Very Short Introduction To node.js<br /><br />Comet with node.js and V8 (amix)<br /><br />Introduction to node.js (JacekBecela)<br /><br />Node.JS references<br /><br />Bex Huff <br /><br />