node js introduction

19
NodeJS Introduction What is Node? (Teaser) How to install/set- up and examples

Upload: joseph-de-castelnau

Post on 17-May-2015

7.549 views

Category:

Technology


3 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Node js introduction

NodeJS Introduction

What is Node? (Teaser)How to install/set-up and examples

Page 2: Node js introduction

Introduction

• Introduction to Node JS• How to Install/Tools• Basic Node concepts (teaser)• Demo

Page 3: Node js introduction

Nodejs Introduction

• NodeJS is built on Google’s V8 Javascript engine• Server-side non blocking asynchronous JS• Perfect for “blood” of Web 2.0 apps (streams,

comet, AJAX, etc) and scale

Page 4: Node js introduction

How to Install (VM) (1/5)

• Download Ubuntu TurnKey from http://www.turnkeylinux.org/core

• Download the free Vmware player from http://www.vmware.com/download/player/thankyou.html

(or use VMWare Workstation)

• Start the Turnkey Virtual Appliance and follow instruction to set-up root password and update security.

• Note IP@ to connect to with SSH

Page 5: Node js introduction

How to Install (SSH) (2/5)

• Get your favorite SSH tool (duh, Putty!)

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

• Set-up your SSH connection as indicated left

• Approve to the RSA key as shown right

Page 6: Node js introduction

How to Install (Misc.) (3/5)

• Get Filezilla http://filezilla-project.org/ if you want to transfer through SSH with your favorite editor

• I use NotePad++ http://notepad-plus-plus.org/with an NppFTP extension http://sourceforge.net/projects/nppftp/ (not automated but easier to remember)

Page 7: Node js introduction

How to Install (Git) (4/5)

• Install Compile toolsapt-get install gccapt-get install g++apt-get install make

• Install Git (would be a good L&L. Volunteers?)apt-get install git-core

• Git the node repo: (alternative is to download & install the TAR’ed version from nodejs but what’s the fun ? wget http://nodejs.org/dist/node-v0.4.12.tar.gz)git clone git://github.com/joyent/node.git

• Make sure to use the latest stable version(As of 10/3/2011, I recommend 0.4.11. 0.4.12 seems to be the latest though) cd nodegit checkout v0.4.11

• Configure/Make./configureMakeMake Install

You are all set:cd benchmark/node v8_bench.js

Page 8: Node js introduction

How to Install (NPM) (5/5)

• Get CURL apt-get install curl

• Install NPMcurl http://npmjs.org/install.sh | sh

• You are all setnpm

Page 9: Node js introduction

What is NPM?

• NPM is a Node Dependency manager (better than APT)

• Get a package, and all dependent package will automatically be installed

Page 10: Node js introduction

Good Node Packages

• Connect

The middleware framework for node: Logging, Cookies, Sessions, Cache, response time …

• Express

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)

• Socket.io

“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)

• Twitternode

A complete node twitter client API wrapper supporting full JSON streams.

Page 11: Node js introduction

Why on earth would I want do do server-side JavaScript?

• Because geeks like to play with new things

• Because you like the open/flexible/powerful nature of a language such as javascript

• You already do a lot of client-side javascript

• You need to “Web” scale• You need to communicate with many other resources

• You do many medium size payloads that could benefit from asynchronous processing

• Many javascript developers and a growing established open-source javascript libraries and code repository

Page 12: Node js introduction

More importantly :

• It’s cool:

• And, it hasn’t jumped the shark (yet?):

Page 13: Node js introduction

Give me the geek version• Performance rocks on many connections, resources

utilization

• No concepts of threads, which is an extremely wasteful idea when trying to server many (thousands) requests

• Streaming (comets) & big data payloads (big .csv reports scaled to thousands) do not scale on thread-based servers

• Non blocking calls can handle way more requests/seconds and use less memory

Source: http://blog.webfaction.com/a-little-holiday-present

Page 14: Node js introduction

So what have we learnt so far?

• Node.JS is using non-blocking, event-based (asynchronous) engine to deliver a much more scalable server

• Javascript is a really natural fit for event-based programming

Page 15: Node js introduction

Events in Node.js

• Relies on event-loop system

• Should be familiar for all developers (.net …) who used events & delegates or others who are familiar with concept of callbacks.

• Javascript is a really natural fit for event-based programming

• Builds on anonymous functions (lamba*)

* Tom will do a L&L on advanced JS (closure, Lambda) concepts shortly

Page 16: Node js introduction

Blocking vs Non BlockingBlocking Non Blocking

Page 17: Node js introduction

Event Loop Demo

Demo!

Page 18: Node js introduction

NodeJS Full Demo

Page 19: Node js introduction

References

• Web faction bloghttp://blog.webfaction.com/a-little-holiday-present

• Understanding event loops and writing great code for node.jshttp://developer.yahoo.com/blogs/ydn/posts/2010/10/understanding-the-event-loops-and-writing-great-code-for-node-js-part-1/

• A Not Very Short Introduction To node.jshttp://blog.jayway.com/2011/05/15/a-not-very-short-introduction-to-node-js/

• Comet with node.js and V8 (amix)http://www.slideshare.net/amix3k/comet-with-nodejs-and-v8

• Introduction to node.js (Jacek Becela)http://www.slideshare.net/jacekbecela/introduction-to-nodejs

• Node.JS referenceshttp://nodejs.org/

• Bex Huff http://bexhuff.com/