1 Agenda Quick'Intro' Node.js:'The'Beginning' What'Is'Node.js? - - PowerPoint PPT Presentation

1 agenda
SMART_READER_LITE
LIVE PREVIEW

1 Agenda Quick'Intro' Node.js:'The'Beginning' What'Is'Node.js? - - PowerPoint PPT Presentation

1 Agenda Quick'Intro' Node.js:'The'Beginning' What'Is'Node.js? Why'Use'Node.js? Installing'Node.js 2 Node.js is a platform for building applications What%makes%Node.js%so%special?


slide-1
SLIDE 1

1

slide-2
SLIDE 2

Agenda

  • Quick'Intro'
  • Node.js:'The'Beginning'
  • What'Is'Node.js?
  • Why'Use'Node.js?
  • Installing'Node.js

2

slide-3
SLIDE 3

Node.js is a platform for building applications

What%makes%Node.js%so%special?

  • It$allows$you$to$run$JavaScript$outside$of$the$browser.
  • Which$means$you$can$build$desktop$apps,$too!
  • It's$really$fast$but..the$reason$for$that$is$a$li@le$

complicated.

  • Let's$give$it$a$li@le$context$by$understanding$how$and$why$

Node$was$created.

3

slide-4
SLIDE 4

4

slide-5
SLIDE 5

Ryan%Dahl

  • Creator(of(Node.js
  • He(first(presented(Node.js(at(a(

JavaScript(Conference(in(2009(

  • He(was(inspired(a<er(watching(

a(Flickr(demo

5

slide-6
SLIDE 6

7

slide-7
SLIDE 7

8

slide-8
SLIDE 8

9

slide-9
SLIDE 9

10

slide-10
SLIDE 10

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.!

What%is%a%JavaScript%Engine?

  • A#program#that#compiles#JavaScript#code#into#na6ve#machine#code.
  • Some6mes#referred#to#as#a#compiler.
  • Example#engines#include:
  • V8#(Google)
  • SpiderMonkey#(Mozilla)
  • JavaScriptCore#(Apple)
  • Chakra#(MicrosoG)

11

slide-11
SLIDE 11

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.!

What%is%a%JavaScript%Run1me?

  • A#library#used#by#the#JavaScript#Engine#to#implement#func;ons#

during#run;me#aka#execu;on#of#a#program.

  • These#libraries#o@en#include#func;ons#for#input/output#and#memory#

management.

  • Example#run;mes#include:
  • Node.js
  • Browsers

12

slide-12
SLIDE 12

Google&Chrome

  • Uses%a%client'side%JavaScript%

Run2me

  • The%Run2me%is%part%of%the%

browser

  • Handles%tasks,%such%as:

13

slide-13
SLIDE 13

Node.js

  • Is$a$server%side$JavaScript$

Run1me

  • Is$installed$on$a$computer$or$

server

  • Handles$tasks,$such$as:
  • Database$queries
  • File$I/O$Requests

14

slide-14
SLIDE 14

15

slide-15
SLIDE 15

Node%is%Event&Driven

Remember&the&JavaScript&Event2Handling&lecture?&

  • When&this&event&happens,&do&this&ac'on.
  • Example:&When&a&user&clicks&this&bu3on,&

display&this&menu.

  • This&is&considered&a&Client-Side&event.

16

slide-16
SLIDE 16

Node%is%Event&Driven

  • Some&common&server,side&events,&include;
  • connect
  • abort
  • open&
  • close
  • Example:&When&this&file&is&open,&append&the&date.

17

slide-17
SLIDE 17

Node%is%Event&Driven

  • Node&is&always&listening&for&new&events
  • Kind&of&like&a&nosy&neighbor&

18

slide-18
SLIDE 18

Node%is%Event&Driven

  • When&Node&recognizes&an&event,&it&sends&the&

rela4ng&ac4on&off&to&process,&then&creates&a& callback.

  • A&callback&is&just&that,&Node&calls&back&that&

ac4on,&so&it&can&answer&another&event.&

  • Example:&When&this&file&is&open,&append&the&

date...brb...Ok,&now&close&the&file.

19

slide-19
SLIDE 19

20

slide-20
SLIDE 20

Node%is%Non$Blocking

  • Non%Blocking,opera1ons,are,some1mes,referred,to,

as,Asynchronous,opera1ons,

  • Other,code,will,execute,while,Node,waits,for,the,

asynchronous,opera1on,to,complete

21

slide-21
SLIDE 21

vs#Blocking

  • Blocking*opera/ons*are*some/mes*referred*to*as*

Synchronous*opera/ons*

  • No*other*code*can*execute*un/l*the*synchronous*
  • pera/on*completes
  • If*the*opera/on*is*slow,*this*can*be*an*issue

22

slide-22
SLIDE 22

23

slide-23
SLIDE 23

Node%is%Single,Threaded

  • A#thread#is#a#single#computer#process
  • Node's#main#Event#Loop#runs#in#a#single#thread
  • Events#and#Callbacks#are#queued#in#the#order#they#

are#received

24

slide-24
SLIDE 24

Event&Loop&Example

  • A#web#request#is#received
  • Node#executes#the#handler#for#that#request
  • The#handler#ini9ates#a#database#query,#with#a#callback
  • Node#is#free#and#able#to#handle#other#requests
  • The#database#query#ends,#and#Node#is#no9fied#(event)
  • Node#adds#the#callback#to#the#queue
  • Node#executes#the#handler#a@er#processing#any#events#

before#it#in#the#queue

25

slide-25
SLIDE 25
slide-26
SLIDE 26

26

slide-27
SLIDE 27

On#It's#Own,#Node#is#NOT...

  • a#web#framework
  • so,#it's#not#a#JavaScript#version#of#Ruby#on#Rails

!

27

slide-28
SLIDE 28

HOWEVER,(when(paired(with...

  • web%frameworks,%such%as%Express%or%AngularJS
  • you%can%create%full5fledged%web%applica;ons

28

slide-29
SLIDE 29

You$can$ALSO$create...

  • desktop)applica.ons
  • video)games
  • chat)rooms
  • remote)controls)for)toy)cars)!

29

slide-30
SLIDE 30

30

slide-31
SLIDE 31

Installa'on)Steps

  • 1. Go%to%h(ps:/

/nodejs.org

  • 2. Click%the%LTS%download%bu(on
  • 3. Open%Installer
  • 4. Follow%prompts%to%complete%the%installaCon

31

slide-32
SLIDE 32

Basic&Node&Terminal&Commands

  • node
  • opens'an'interac-ve'shell'where'you'can'execute'

JavaScript'code

  • node file_name.js
  • executes'JavaScript'code'that'is'in'a'file'
  • node -v'
  • displays'the'version'of'Node'installed'on'your'

computer

32

slide-33
SLIDE 33

Exercise(#1:!Hello!Node!

  • Using'the'Node'interac1ve'shell,'output'Hello

Node!'in'the'terminal

  • Save'a'Hello Node!'script'in'a'file'and'execute'

that'file'in'the'Terminal

33