Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
NodeJS for Novices - 28/Oct/13 - Winnipeg, MB
1. 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
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 ON TWITTER
DAVIDWESST.COM ON THE WEB
DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE
DW [AT] DAVIDWESST.COM ON EMAIL
6. 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?
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 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
12. 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.
13. WHAT IS NODEJS?
Node is...
...Server-Side JavaScript
...100% Multi-Platform
...Open Source
...Sponsored by Joyent
14. 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]
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)
25. 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
26. 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)
28. CORE TOOLBOX: TEXT EDITOR + 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
Hosted IDE
Free and Paid Options
Open Source
Provides support for major web platforms
Includes other common development features, like MySQL
and Terminal
34. 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
36. 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
37. 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
41. 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!
44. 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
48. NODEJS AND MICROSOFT
Websites and Cloud Services support in Windows Azure
IDE built into WebMatrix
IIS and IIS Support through IISNode
49. 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)
50. 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
52. 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)
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 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?
56. THE POINT
THEME FOR THIS PRESENTATION
UNDERSTAND WHAT YOU
CAN DO WITH NODEJS
59. NEXT STEPS
CHECK OUT A 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 ON TWITTER
DAVIDWESST.COM ON THE WEB
DAVIDWESST.COM/BLOG ON THE BLOGOSPHERE
DW [AT] DAVIDWESST.COM ON EMAIL