This is the slide deck from the popular "Introduction to Node.js" webinar with AMD and DevelopIntelligence, presented by Joshua McNeese. Watch our AMD Developer Central YouTube channel for the replay at https://www.youtube.com/user/AMDDevCentral.
3. Agenda
What is Node.js?
How does it work?
What is it good for?
Some cool examples
Where can you learn more?
4. Node.js history
First published in 2009 by Ryan Dahl, sponsored
by Joyent
Inspired by the file upload bar on Flickr
npm introduced in 2011
Microsoft partnered with Joyent in 2011 to
provide a native Windows version
Dahl stepped aside as project lead in 2012 to
pursue new research projects
5. The future is bright!
After 5 years since its release
3rd most popular project on Github
2 million downloads a month
Over 20 million downloads of v0.10+
In use by large brands such as Goldman Sachs, eBay,
Conde Nast, Dow Jones, Apple, Yahoo and many more
Companies are hiring
Since Jan `10, the number of Node.js positions have
increased more than 90,000%
Interest is high
Google search trends have increased year over year,
even when other “hot” technologies decline (RoR) or
remain the same (Obj-C)
6. So what is Node.js?
“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.”
7. Uh… what?
Unless you are already familiar with real-time
application development, this possibly sounds
like techno-babble
So let’s break that down!
8. It’s JavaScript!
Code is parsed using Google’s V8 JavaScript
engine, originally developed for Chrome
The good news is that if you already know
JavaScript, learning Node.js is fairly easy
The bad news is that it’s not like the front-end
JavaScript you are probably familiar with
9. It’s event-driven
Much like frontend JavaScript, Node.js code
executes in an “event loop”
10. What is an “Event Loop”?
According to MDN: “The Event Loop is a queue
of callback functions. When an async function
executes, the callback function is pushed into
the queue. The JavaScript engine doesn't start
continue processing the event loop until the
code after an async function has executed.”
11. Non-blocking I/O
Working hand-in-hand with JavaScript’s
asynchronous nature, any I/O is delegated to a
separate pool of threads
Callbacks to execute once I/O operations are
completed are added to the event loop for future
execution
This is one of the cornerstones of Node’s speed
and scalability
Why? Because I/O is expensive
14. NPM
Bundled with Node.js, similar to CPAN, PEAR,
Ruby gems or Python eggs
There’s pretty much a package for everything*
Impressive stats:
> 104k packages
> 146 million downloads last week
> 599 million downloads last month
Super easy to use:
npm install express
16. Some cool examples
A webserver in 5 lines? Preposterous!
Query a pooled mysql connection? No problem!
17. Streams too?
Most I/O is handled by streams, so it’s easy to
do things like encrypt, compress or otherwise
modify streaming data:
18. What is it good for?
Node.js is good for lightweight, non-CPU
intensive network applications
APIs
Real-time applications, pub/sub, chat servers
Streaming data
Proxies
Command-line utilities
Remember that Node.js is still in “beta”, but can
be successfully deployed in production
environments
19. Where can you learn more?
Node.js Info
http://nodejs.org
http://howtonode.org
http://www.npmjs.org
http://www.codewars.com
http://www.developintelligence.com/catalog/web-development-training/
nodejs
Developer Info
Learn about future webinars with AMD Developer Central:
http://developer.amd.com
Watch this webinar replay: www.youtube.com/user/AMDDevCentral
Learn when the replay is posted: Follow @AMDDevCentral on
Twitter
Download this deck: http://www.slideshare.net/DevCentralAMD
1m
I say that jokingly as if this is a support group for embarrased internet engineers, since it used to be that being a “javascript programmer” was an embarrassing thing… but today it is exciting to be a javascript programmer, particularly so with technologies like node.js.
20 years in internet industry
Developer for past 100… uh 14 years
Using javascript for past 8 years
Time is mostly equally divided between node.js and php currently
Live in colorado with my wife, son, two cats and dog
3m
Dahl was inspired to create Node.js after seeing a file upload progress bar on Flickr. The browser did not know how much of the file had been uploaded and had to query the Web server. Dahl desired an easier way.[15]
Dahl decided to use the v8 engine due to it being open source, and because there weren’t any viable non-blocking i/o models for javascript in a server context at the time
3m
Researched by StrongLoop
Job stats from Indeed
Search stats from Google
1m
According to the website…
I thought the coolest thing javascript could do was the canvas element!
3m
By default, node.js supports ES5, although many of ES6 features can be enabled
5m
Describe how js executes code sequentially and blocking like front-end javascript, but leverages callbacks to maintain non-blocking overall execution
Highlight similarity to frontend javascript’s event loop, using the DOM and browser events
3m
An event loop is "an entity that handles and processes external events and converts them into callback invocations". So I/O calls are the points at which Node.js can switch from one request to another. At an I/O call, your code saves the callback and returns control to the node.js runtime environment. The callback will be called later when the data actually is available.
This is part of the reason why node.js is efficient, in that it uses every opportunity available to continue processing the main event loop, without waiting for long-running threads to complete executing
One main difference between node.js’s eventloop vs. other event-driven frameworks like EventMachine for ruby, or twisted for python is that this functionality is transparently part of the runtime, and not a structure built on top of the language. You don’t have to remember to engage the event loop, the node process enters it immediately upon execution, and when there is no longer any callbacks to execute, it exits.
4m
This pool is managed by libuv, created by Joyent
It’s been said: “the largest waste with current programming technologies comes from waiting for I/O to complete”
2m
A multithreaded server such as apache or tomcat
2m
No clients waiting on acknowledgement of their request (while they may be waiting on a response!)
3m
And if there isn’t, go build one! The community loves new packages.
Modules can easily be build with javascript, but “heavier” or more proprietary modules can be built with C/C++