NODE FOR NOVICES
BRINGING JAVASCRIPT TO THE SERVER
An original presentation by David Wesst / @davidwesst

PRESENTED AT THE WINNIPEG .NET USER GROUP - OCTOBER 28, 2013
http://www.winnipegdotnet.org
DAVID WESST

FROM WINNIPEG, MANITOBA
SYSTEMS ANALYST, UNIVERSITY OF MANITOBA (FACULTY OF
MEDICINE)
MICROSOFT MVP, INTERNET EXPLORER
IE USER AGENT USERAGENTS.IE
PRODUCER, BREWPUB STUDIOS
DAVID WESST

@DAVIDWESST ON TWITTER
DAVIDWESST.COM ON THE WEB
DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE
DW [AT] DAVIDWESST.COM ON EMAIL
FOLLOW ALONG

HTTP://DAVIDWESST.GITHUB.IO/DW-PRESENTATIONS
SLIDES AND DEMOS WILL
BE MADE AVAILABLE
AFTERWARDS
THE POINT

TO ANSWER ONE OF THE FOLLOWING QUESTIONS:
What is Node (a.k.a. NodeJS)?
What do I need to get started?
What makes NodeJS different to ASP.NET?
Why aren't my JS frameworks working in NodeJS?
THE POINT

THEME FOR THIS PRESENTATION

UNDERSTAND WHAT YOU
CAN DO WITH NODEJS
THE PLAN (A.K.A. THE AGENDA)
How are we going to do this?
What is NodeJS?
Getting Yourself Setup
Your NodeJS Toolbox
Getting Your Node On
THE PLAN

SETTING YOUR EXPECTATIONS
This presentation is...
An introduction to NodeJS
A dialogue about NodeJS
Comparing NodeJS to ASP.NET
A review of NodeJS development tools
A "core sample" of NodeJS fundamentals
WHAT IS NODEJS?
WHAT IS NODEJS?

"NODE" = "NODEJS"
WHAT IS NODEJS?
Node is...
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.
WHAT IS NODEJS?
Node is...
...Server-Side JavaScript
...100% Multi-Platform
...Open Source
...Sponsored by Joyent
WHAT IS NODEJS?
Node is...
...Powered by Google's V8 JavaScript Engine
...Provides request-level control
...bundled with a package manager (a.k.a npm, node packaged
modules)
...Built on the idea of Asynchronous I/O [or Non-Blocking I/O]
ASYNCHRONOUS I/O?
I/O THAT DOESN'T BLOCK YOUR APPLICATION
YOU: I DON'T
UNDERSTAND HOW THAT
IS POSSIBLE. TELL ME
MORE!
I WILL.
EXAMPLE: CLIENT-SIDE JAVASCRIPT
/ fn t o w t pr mt r
/ u ci n ih a ae e
f nt o mC in Fn to ( es g, cl bc ) {
u ci n yl et u ci nm sa e a la k
/ v ra l
/ a i be
v rm g =m sa e
a s
e sg ;
/ o jc s
/ bet
v rr n oA ry =n wA r y)
a ad mr a
e ra (;
/ f nt o cl
/ u c in al
ae tm g;
lr ( s)
/ c l te cl bc
/ a l h al a k
cl bc (;
al a k)
}
;
v rt ea la k= f nt o( {
a h C lb c
u ci n )
/ .. o sm ti g
/. d oe hn
}
m Ci nF nt o( e sg ,t ea l ak ;
y le t uc in ms ae hC lb c)
EXAMPLE: SERVER-SIDE (NODEJS)
JAVASCRIPT
/ fn t o w t pr mt r
/ u ci n ih a ae e
f nt o mS re Fn to ( es g, cl bc ) {
u ci n ye vr u ci nm sa e a la k
/ v ra l
/ a i be
v rm g =m sa e
a s
e sg ;
/ o jc s
/ bet
v rr n oA ry =n wA r y)
a ad mr a
e ra (;
/ f nt o cl
/ u c in al
cn oe lg mg ;
os l .o (s )
/ c l te cl bc
/ a l h al a k
cl bc (;
al a k)
}
;
v rt ea la k= f nt o( {
a h C lb c
u ci n )
/ .. o sm ti g
/. d oe hn
}
m Sr eF nt o( e sg ,t ea l ak ;
y ev r uc in ms ae hC lb c)
THE SECRET IS...

CALLBACKS
CALLBACKS

CALLBACK ARE THE SECRET TO NON-BLOCKING OPERATIONS
On the client, UI is kept unblocked
On the server, Requests are unblocked
OPTIONAL DEMO:
CALLBACKS
WHERE IS NODE BEING USED IN
PRODUCTION?
REAL EXAMPLES

Nodejitsu, Cloud Platform
LinkedIn
Ebay
LET'S TALK NODEJS AND
JAVASCRIPT
FRAMEWORKS (LIKE
BACKBONEJS)
GETTING YOURSELF
SETUP
WHAT ARE YOU GOING TO NEED?
Your development machine (Windows, Linux, or Mac)
An Internet Connection
(OPTIONAL) A bit of comfort with a command line
HOW ARE YOU GOING TO DO IT?
WINDOWS AND MAC
1.
2.
3.
4.

Go to NodeJS.org
Download the installer
Follow the install wizard
Test it in the CLI (command line interface)
YOUR NODEJS TOOLBOX
CORE TOOLBOX: TEXT EDITOR + TERMINAL
THIS IS PRETTY GOOD TO GET YOU GOING
Vi
Notepad
GEdit
TextMate
NODEJS TOOLS: NODECLIPSE / NODE IDE
HTTP://WWW.NODECLIPSE.ORG/

Eclipse Plugin(s)
Free and Open Source
Adds NodeJS running and debugging support in Eclipse
Very young project, but provides what you need
NODEJS TOOLS: CLOUD9
HTTP://C9.IO

Hosted IDE
Free and Paid Options
Open Source
Provides support for major web platforms
Includes other common development features, like MySQL
and Terminal
NODEJS TOOLS: WEBMATRIX

HTTP://WWW.MICROSOFT.COM/WEB/WEBMATRIX/
Windows Application from Microsoft
Free
Environment for popular web platforms (Node, Rails, PHP,
HTML5, ASP.NET)
Meant for development of Web Sites over Web Apps
NODEJS TOOLS
WebStorm IDE by JetBrainsLink
Netbeans Plugin Link
Visual Node (Private Beta) by RedgateLink
GETTING YOUR NODE ON
WARMING UP TO NODE

NODE PROJECTS ARE MADE UP OF THE FOLLOWING:
"App.js" - Your Main Executable File
"Package.json" (OPTIONAL) - Describes details of your
application
"node_modules/" (OPTIONAL) - Contains project
dependencies
DEMO

INTRODUCING NODEJS
USING THE NPM

NODE PACKAGED MODULES
NPM is bundled with Node base install as of v0.6.3
Packages can be browsed at NPMjs.org
Installs packages either locally
n mi sa lu dr c r
p n t l ne so e

...or globally
n mi sa l- t ps rp
p n t l g y e ci t
PACKAGE.JSON: REVISITED
THE KEYS TO USING THE NPM

You can...
Define dependencies for running your application
Define dependencies for developing your application
Set the name, version, and main for your own apps and
packages
Publish your own packages to the npm
DEMO: USING NPM
COMMAND LINE
PRO TIP
GITHUB IS YOUR FRIEND
CODING WITH CALLBACKS

USING THE REAL POWER OF NODEJS
Keys to remember:
Functions are first-class citizens in JavaScript
Functions can be passed as arguments
Defining functions inside of functions makes them "private"
Non-blocking means user waits less, which is good!
CODING WITH CALLBACKS
DEMO

CODING WITH CALLBACKS
MAKING YOUR OWN MODULES
MODULARITY FOR THE WIN

Keys to remember:
Modules provide a way to easily organize your code
Can be shared amongst other projects
Published through npm or git repository
Version is defined in package.json
DEMO

MAKING YOUR OWN MODULES
THINGS TO REMEMBER
Private and Public variables exist
Think Modular
NPM is your friend
...and so is Github
LET'S TALK NODEJS AND
MICROSOFT STUFF
NODEJS AND MICROSOFT
Websites and Cloud Services support in Windows Azure
IDE built into WebMatrix
IIS and IIS Support through IISNode
ASP.NET VS NODEJS
Serves up JavaScript and HTML
Natively Synchronous
Requires IIS
Provides multiple structured ways of doing web (Web Forms,
MVC, Websites, WebAPI)
ASP.NET VS NODEJS
Serves up JavaScript and HTML
Natively Asynchronous
Does not require web server (e.g. IIS)
Provides multiple unstructured ways of doing web
Open Source
PRO TIP
EXPRESSJS: YOUR NEW FAVOURITE NODE
MODULE
POPULAR MVC FRAMEWORK FOR NODE

Provides MVC Pattern for Web Applications
Supports Popular Middle Modules
Command-Line Setup
Supports popular UI tools (e.g. LESS, SASS, Jade Templates)
DEMO

INTRODUCTION EXPRESSJS
THE PLAN (A.K.A. THE AGENDA)
How are we going to do this?
What is NodeJS?
Getting Yourself Setup
Your NodeJS Toolbox
Getting Your Node On
THE POINT

TO ANSWER ONE OF THE FOLLOWING QUESTIONS:
What is Node (a.k.a. NodeJS)?
What do I need to get started?
What makes NodeJS different to ASP.NET?
Why aren't my JS frameworks working in NodeJS?
THE POINT

THEME FOR THIS PRESENTATION

UNDERSTAND WHAT YOU
CAN DO WITH NODEJS
NEXT STEPS
Where do we go from here?
NEXT STEPS
Install NodeJS
Create a NodeJS Application with or without ExpressJS
Explore the npm
Publish a package to the npm
NEXT STEPS

CHECK OUT A RESOURCE
http://package.json.nodejitsu.com/
http://blog.nodejitsu.com/npm-cheatsheet
http://npmjs.org
DAVID WESST

FROM WINNIPEG, MANITOBA
SYSTEMS ANALYST, UNIVERSITY OF MANITOBA (FACULTY OF
MEDICINE)
MICROSOFT MVP, INTERNET EXPLORER
IE USER AGENT USERAGENTS.IE
PRODUCER, BREWPUB STUDIOS
DAVID WESST

@DAVIDWESST ON TWITTER
DAVIDWESST.COM ON THE WEB
DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE
DW [AT] DAVIDWESST.COM ON EMAIL

NodeJS for Novices - 28/Oct/13 - Winnipeg, MB

  • 1.
    NODE FOR NOVICES BRINGINGJAVASCRIPT TO THE SERVER An original presentation by David Wesst / @davidwesst PRESENTED AT THE WINNIPEG .NET USER GROUP - OCTOBER 28, 2013 http://www.winnipegdotnet.org
  • 2.
    DAVID WESST FROM WINNIPEG,MANITOBA SYSTEMS ANALYST, UNIVERSITY OF MANITOBA (FACULTY OF MEDICINE) MICROSOFT MVP, INTERNET EXPLORER IE USER AGENT USERAGENTS.IE PRODUCER, BREWPUB STUDIOS
  • 3.
    DAVID WESST @DAVIDWESST ONTWITTER DAVIDWESST.COM ON THE WEB DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE DW [AT] DAVIDWESST.COM ON EMAIL
  • 4.
  • 5.
    SLIDES AND DEMOSWILL BE MADE AVAILABLE AFTERWARDS
  • 6.
    THE POINT TO ANSWERONE OF THE FOLLOWING QUESTIONS: What is Node (a.k.a. NodeJS)? What do I need to get started? What makes NodeJS different to ASP.NET? Why aren't my JS frameworks working in NodeJS?
  • 7.
    THE POINT THEME FORTHIS PRESENTATION UNDERSTAND WHAT YOU CAN DO WITH NODEJS
  • 8.
    THE PLAN (A.K.A.THE AGENDA) How are we going to do this? What is NodeJS? Getting Yourself Setup Your NodeJS Toolbox Getting Your Node On
  • 9.
    THE PLAN SETTING YOUREXPECTATIONS This presentation is... An introduction to NodeJS A dialogue about NodeJS Comparing NodeJS to ASP.NET A review of NodeJS development tools A "core sample" of NodeJS fundamentals
  • 10.
  • 11.
  • 12.
    WHAT IS NODEJS? Nodeis... 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.
  • 13.
    WHAT IS NODEJS? Nodeis... ...Server-Side JavaScript ...100% Multi-Platform ...Open Source ...Sponsored by Joyent
  • 14.
    WHAT IS NODEJS? Nodeis... ...Powered by Google's V8 JavaScript Engine ...Provides request-level control ...bundled with a package manager (a.k.a npm, node packaged modules) ...Built on the idea of Asynchronous I/O [or Non-Blocking I/O]
  • 15.
    ASYNCHRONOUS I/O? I/O THATDOESN'T BLOCK YOUR APPLICATION
  • 16.
    YOU: I DON'T UNDERSTANDHOW THAT IS POSSIBLE. TELL ME MORE! I WILL.
  • 17.
    EXAMPLE: CLIENT-SIDE JAVASCRIPT /fn t o w t pr mt r / u ci n ih a ae e f nt o mC in Fn to ( es g, cl bc ) { u ci n yl et u ci nm sa e a la k / v ra l / a i be v rm g =m sa e a s e sg ; / o jc s / bet v rr n oA ry =n wA r y) a ad mr a e ra (; / f nt o cl / u c in al ae tm g; lr ( s) / c l te cl bc / a l h al a k cl bc (; al a k) } ; v rt ea la k= f nt o( { a h C lb c u ci n ) / .. o sm ti g /. d oe hn } m Ci nF nt o( e sg ,t ea l ak ; y le t uc in ms ae hC lb c)
  • 18.
    EXAMPLE: SERVER-SIDE (NODEJS) JAVASCRIPT /fn t o w t pr mt r / u ci n ih a ae e f nt o mS re Fn to ( es g, cl bc ) { u ci n ye vr u ci nm sa e a la k / v ra l / a i be v rm g =m sa e a s e sg ; / o jc s / bet v rr n oA ry =n wA r y) a ad mr a e ra (; / f nt o cl / u c in al cn oe lg mg ; os l .o (s ) / c l te cl bc / a l h al a k cl bc (; al a k) } ; v rt ea la k= f nt o( { a h C lb c u ci n ) / .. o sm ti g /. d oe hn } m Sr eF nt o( e sg ,t ea l ak ; y ev r uc in ms ae hC lb c)
  • 19.
  • 20.
    CALLBACKS CALLBACK ARE THESECRET TO NON-BLOCKING OPERATIONS On the client, UI is kept unblocked On the server, Requests are unblocked
  • 21.
  • 22.
    WHERE IS NODEBEING USED IN PRODUCTION? REAL EXAMPLES Nodejitsu, Cloud Platform LinkedIn Ebay
  • 23.
    LET'S TALK NODEJSAND JAVASCRIPT FRAMEWORKS (LIKE BACKBONEJS)
  • 24.
  • 25.
    WHAT ARE YOUGOING TO NEED? Your development machine (Windows, Linux, or Mac) An Internet Connection (OPTIONAL) A bit of comfort with a command line
  • 26.
    HOW ARE YOUGOING TO DO IT? WINDOWS AND MAC 1. 2. 3. 4. Go to NodeJS.org Download the installer Follow the install wizard Test it in the CLI (command line interface)
  • 27.
  • 28.
    CORE TOOLBOX: TEXTEDITOR + TERMINAL THIS IS PRETTY GOOD TO GET YOU GOING Vi Notepad GEdit TextMate
  • 29.
    NODEJS TOOLS: NODECLIPSE/ NODE IDE HTTP://WWW.NODECLIPSE.ORG/ Eclipse Plugin(s) Free and Open Source Adds NodeJS running and debugging support in Eclipse Very young project, but provides what you need
  • 30.
    NODEJS TOOLS: CLOUD9 HTTP://C9.IO HostedIDE Free and Paid Options Open Source Provides support for major web platforms Includes other common development features, like MySQL and Terminal
  • 31.
    NODEJS TOOLS: WEBMATRIX HTTP://WWW.MICROSOFT.COM/WEB/WEBMATRIX/ WindowsApplication from Microsoft Free Environment for popular web platforms (Node, Rails, PHP, HTML5, ASP.NET) Meant for development of Web Sites over Web Apps
  • 32.
    NODEJS TOOLS WebStorm IDEby JetBrainsLink Netbeans Plugin Link Visual Node (Private Beta) by RedgateLink
  • 33.
  • 34.
    WARMING UP TONODE NODE PROJECTS ARE MADE UP OF THE FOLLOWING: "App.js" - Your Main Executable File "Package.json" (OPTIONAL) - Describes details of your application "node_modules/" (OPTIONAL) - Contains project dependencies
  • 35.
  • 36.
    USING THE NPM NODEPACKAGED MODULES NPM is bundled with Node base install as of v0.6.3 Packages can be browsed at NPMjs.org Installs packages either locally n mi sa lu dr c r p n t l ne so e ...or globally n mi sa l- t ps rp p n t l g y e ci t
  • 37.
    PACKAGE.JSON: REVISITED THE KEYSTO USING THE NPM You can... Define dependencies for running your application Define dependencies for developing your application Set the name, version, and main for your own apps and packages Publish your own packages to the npm
  • 38.
  • 39.
  • 40.
  • 41.
    CODING WITH CALLBACKS USINGTHE REAL POWER OF NODEJS Keys to remember: Functions are first-class citizens in JavaScript Functions can be passed as arguments Defining functions inside of functions makes them "private" Non-blocking means user waits less, which is good!
  • 42.
  • 43.
  • 44.
    MAKING YOUR OWNMODULES MODULARITY FOR THE WIN Keys to remember: Modules provide a way to easily organize your code Can be shared amongst other projects Published through npm or git repository Version is defined in package.json
  • 45.
  • 46.
    THINGS TO REMEMBER Privateand Public variables exist Think Modular NPM is your friend ...and so is Github
  • 47.
    LET'S TALK NODEJSAND MICROSOFT STUFF
  • 48.
    NODEJS AND MICROSOFT Websitesand Cloud Services support in Windows Azure IDE built into WebMatrix IIS and IIS Support through IISNode
  • 49.
    ASP.NET VS NODEJS Servesup JavaScript and HTML Natively Synchronous Requires IIS Provides multiple structured ways of doing web (Web Forms, MVC, Websites, WebAPI)
  • 50.
    ASP.NET VS NODEJS Servesup JavaScript and HTML Natively Asynchronous Does not require web server (e.g. IIS) Provides multiple unstructured ways of doing web Open Source
  • 51.
  • 52.
    EXPRESSJS: YOUR NEWFAVOURITE NODE MODULE POPULAR MVC FRAMEWORK FOR NODE Provides MVC Pattern for Web Applications Supports Popular Middle Modules Command-Line Setup Supports popular UI tools (e.g. LESS, SASS, Jade Templates)
  • 53.
  • 54.
    THE PLAN (A.K.A.THE AGENDA) How are we going to do this? What is NodeJS? Getting Yourself Setup Your NodeJS Toolbox Getting Your Node On
  • 55.
    THE POINT TO ANSWERONE OF THE FOLLOWING QUESTIONS: What is Node (a.k.a. NodeJS)? What do I need to get started? What makes NodeJS different to ASP.NET? Why aren't my JS frameworks working in NodeJS?
  • 56.
    THE POINT THEME FORTHIS PRESENTATION UNDERSTAND WHAT YOU CAN DO WITH NODEJS
  • 57.
    NEXT STEPS Where dowe go from here?
  • 58.
    NEXT STEPS Install NodeJS Createa NodeJS Application with or without ExpressJS Explore the npm Publish a package to the npm
  • 59.
    NEXT STEPS CHECK OUTA RESOURCE http://package.json.nodejitsu.com/ http://blog.nodejitsu.com/npm-cheatsheet http://npmjs.org
  • 60.
    DAVID WESST FROM WINNIPEG,MANITOBA SYSTEMS ANALYST, UNIVERSITY OF MANITOBA (FACULTY OF MEDICINE) MICROSOFT MVP, INTERNET EXPLORER IE USER AGENT USERAGENTS.IE PRODUCER, BREWPUB STUDIOS
  • 61.
    DAVID WESST @DAVIDWESST ONTWITTER DAVIDWESST.COM ON THE WEB DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE DW [AT] DAVIDWESST.COM ON EMAIL