Node js introduction

9,006 views

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 http://www.turnkeylinux.org/core<br />Download the free Vmware player from http://www.vmware.com/download/player/thankyou.html<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 />http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html<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 http://filezilla-project.org/ if you want to transfer through SSH with your favorite editor<br />I use NotePad++ http://notepad-plus-plus.org/with an NppFTP extension http://sourceforge.net/projects/nppftp/ (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 http://nodejs.org/dist/node-v0.4.12.tar.gz)<br />gitclone git://github.com/joyent/node.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 http://npmjs.org/install.sh | 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 asp.net) (Routing, content negotiations, configurations, etc) <br />Socket.io<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: http://blog.webfaction.com/a-little-holiday-present<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 />http://blog.webfaction.com/a-little-holiday-present<br />Understanding event loops and writing great code for node.js<br />http://developer.yahoo.com/blogs/ydn/posts/2010/10/understanding-the-event-loops-and-writing-great-code-for-node-js-part-1/<br />A Not Very Short Introduction To node.js<br />http://blog.jayway.com/2011/05/15/a-not-very-short-introduction-to-node-js/<br />Comet with node.js and V8 (amix)<br />http://www.slideshare.net/amix3k/comet-with-nodejs-and-v8<br />Introduction to node.js (JacekBecela)<br />http://www.slideshare.net/jacekbecela/introduction-to-nodejs<br />Node.JS references<br />http://nodejs.org/<br />Bex Huff <br />http://bexhuff.com/<br />

×