introduction to nodejs
Post on 18-Sep-2014
26 Views
Preview:
DESCRIPTION
TRANSCRIPT
NodeJS - © Claudio Cicali
What the frak is Node JS?
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Claudio Cicali
@caludio
Front-end engineer at SponsorPay
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Installing NodeJS
Download, unpack, make, make install
... or use homebrew
(and yes! It works on Windows too)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
JavaScript is an interpreted languagewhich means that you need an JavaScript
interpreter to run your programs
We often refer to these beastsas JavaScript Engines or
JavaScript Virtual Machine
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Every browser has its own VM
Firefox? SpidermonkeyInternet Explorer? Chakra
Chrome? V8Safari? JavaScriptCore
Opera? Carakan
Also Rhino, stand alone
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
2009: this guy had an idea
(he is Ryan Dahl, btw)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Make no mistake
NodeJS is NOT a “one man project”
It is backed by Joyent, which is a big playerin the cloud computing business
(has money and people)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
If you already can write JavaScriptin the browser why can’t you writeJavaScript on the server then?
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
js VMs are getting better and better
Get one of them, include someadditional libraries and wrap it up
into a powerful, directly executableJavaScript platform
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
After the idea, the design:
Google V8 would have been the VM(Tried using Spidermonkey, no luck)
Monoprocess, no threads
Completely event driven (asynchronous, non-blocking)
Focus on NETWORKING
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
What is the “Node Standard Library”?
A set of ready-to-use tools which gives you
- a powerful HTTP(S) library (client and server in no time)- DNS name resolution- Crypto- access to the file system- URL manipulation- ZLIB- UDP datagrams
http://nodejs.org/docs/latest/api/
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Those tools can JavaScript onlyor mixed with some C or C++
for performances reason
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Now we have a platform to write REAL programs(i.e.: no sandboxing) in JavaScript
The JavaScript itself - oh, joy - it’s the latest stable V8
AND NO COMPATIBILITY LAYER! (cries)
except ...
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
... except for Node JS itself
With every new major version, you mightloose compatibility at the API level
(the Node standard library)
(this is really more of a youth problem, anyway)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Node JS is fast, in theory
Low maintencance (small impact on resources)
Programs must not stress the CPU
Programming is not THAT easy
API are well documented
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
The Node JS standard library can be EXTENDED by the use of
modules
This is serious business: the number of available modules is
HUGE
(and the quality? Well...)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
MODULES in NodeJS use a well knownpattern/paradigm/standard: CommonJS(which is well known thanks to... NodeJS)
Writing a module is easy
Maybe too much :)
(oh, and you’d write “addons” in C/C++ as well)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Take a look:
https://github.com/joyent/node/wiki/modules
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Module management is EASY with
https://npmjs.org/
No need to install it: comes with Node!(Node >= 0.6)
With brew you need to run npmjs.org/install.sh
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Need to access MySQL from your program?
npm install mysql
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Publishing your module to the worldis freacking easy too
(no moderation, no approval...)
npm publish
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Modules can be of any complexity
Connect is a big “middleware” modulewhich gives you cookies, sessions, logging,
caching...
Express is a web framework built on top of Connect
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
// The “fs” module is ready to usevar fs = require(“fs”);
fs.open(“somefile”, “r”, function(error) {
// Do something with the file
});
What “using modules” means
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
claudioc$ npm install sqlite
// Once installed the “sqlite” module is// ready to usevar sqlite = require(“sqlite”);
var db = new sqlite.Database();
db.open(“my_db”, function(error) {
// Do something with the database
});
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
There are libraries which run in the browserAND in NodeJS as modules (transparently)
“As of 3.5.0, YUI runs natively on Node.js and comes with an official npm package for easy installation.”
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
What can NodeJS be used for then?
Network servers (HTTP, Proxies, messaging)
API backends
Real time applications
Streaming data
“One page” web sites
Command line tools
BotsTuesday, December 4, 2012
NodeJS - © Claudio Cicali
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Let me introduce you a coupleof things I’ve done with NodeJS
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
antipad.comReal time collaborative code editor
Built on the giants’ shoulders:
The ACE editor (awesome)
The ShareJS library (super awesome)
NodeJS (lovely)
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
jecho
“Poor man” command line remote debuggerfor mobile devices
https://github.com/claudioc/jecho
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
I want moar!
http://www.nodebeginner.org/(highly recommended)
http://nodetoolbox.com
http://nodeguide.com
Tuesday, December 4, 2012
NodeJS - © Claudio Cicali
Follow me! @caludioTuesday, December 4, 2012
NodeJS - © Claudio Cicali
One more thing
“The guys that are getting paid the big bucks to deliver scalable solutions aren’t up at night feverishly rewriting their systems in Node. They’re doing what they’ve always done: measuring, testing, benchmarking, thinking hard, keeping up with the academic literature that pertains to their problems.”
-- Alex Payne
http://al3x.net/2010/07/27/node.html
Tuesday, December 4, 2012
top related