Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node.js: een introductie

Avatar for mattijs mattijs
October 11, 2011

Node.js: een introductie

Node.js introductie presentatie gegeven op #hackersNL

Avatar for mattijs

mattijs

October 11, 2011
Tweet

Other Decks in Technology

Transcript

  1. Over mij • Mattijs Hoitink (mattijs) • Informatica gestudeerd •

    Eerst zelfstandig ondernemer • Nu in loondiest • Ultimate Frisbee • Node.js gebruiker sinds een jaar
  2. Vanavond • Node(.js) • Javascript • Hoe zit het er

    uit • Een paar stukjes code • Hoe kun je het gebruiken • Het ecosysteem • Dodo's
  3. Javascript "JavaScript, purely by accident, has become the most popular

    programming language in the world. There are more JavaScript processors in the world than any other language by far." Douglas Crockford, Coders at Work, 2009 Coders at Work, Peter Siebel, 2009, ISBN 978-1-4302-1949-1
  4. Javascript Wie gebruikt er hier JavaScript? Wie vindt JavaScript een

    fijne taal? Wie gebruikt er jQuery? Waarom?
  5. Node(.js) My next project I'm going to 1. write a

    special thin web server tied to the V8 javascript interpreter (Mongrel for V8 if you will) 2. write a special evented TCP library for V8 (probably by wrapping liboi). Does this exist in public already? Certainly google has such
  6. Voorbeeldje var http = require('http'); http.createServer(function (req, res) { res.writeHead(200,

    {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
  7. Ontgroening Platform voor realtime interactie gesynchroniseerd met televisie programma's •

    Android, iOS, BlackBerry, Laptop • 50.000+ gelijktijdige clients • Chrome, Safari, Firefox, Internet Explorer, Opera • Websockets • Node!
  8. Ontgroening (2) • Alles asynchroon • Overal callbacks • Compilen

    • Javascript • Snelle ontwikkelingen • Performance • HTTP powered
  9. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type':

    'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/'); Voorbeeldje uitgebreid
  10. Voorbeeldje uitgebreid var http = require('http'); var message = 'Hello

    World'; http.createServer(function(req, res) { var body = ''; req.on('data', function(chunk) { body += chunk; }); req.on('end', function() { if ('POST' == req.method) { message = body }; res.writeHead(200).end(); }); }).listen(1338); console.log('Server2 running at http://127.0.0.1:1338'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(message); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
  11. • Process • Utilities • Events • Buffers • Streams

    • Crypto • TLS/SSL • String Decoder • File System • Path • Net • UDP/Datagram • DNS • HTTP • HTTPS • URL • Query Strings • Readline • REPL • VM • Child Processes • Assertion Testing • TTY • OS Modules! Core Modules
  12. Modules! var http = require('http'); // core var http =

    require('othermodule'); // systeem var http = require('./mymodule'); // relatief
  13. Modules! var util = require('util'); var super = require('./super'); var

    Lois = require('./lois'); fuction Clark() { this.name = 'Clark Kent'; this.job = 'Reporter'; } util.inherits(Clark, super.Man); module.exports = { Clark: Clark, disappear: function(clark) { clark.undress(); clark.saveLois(Lois.find()); clark.dress(); return clark; } };
  14. NPM > npm install package > npm install package@version >

    npm install . > npm install https://github.com/LearnBoost/socket.io/tarball/master > npm install -g package
  15. Ecosysteem > npmtop rank percent packages author ---- ------- --------

    ------ 1 1.61 % 67.00 James Halliday 2 1.59 % 66.00 TJ Holowaychuk 3 1.42 % 59.00 AJ ONeal 4 1.13 % 47.00 Dominic Tarr 5 0.82 % 34.00 Craig Condon 6 0.79 % 33.00 Marak Squires 7 0.72 % 30.00 Isaac Z. Schlueter 8 0.70 % 29.00 Nickolay Platonov 9 0.63 % 26.00 Charlie Robbins 10 0.60 % 25.00 Felix Geisendörfer 11 0.58 % 24.00 George Stagas 12 0.53 % 22.00 Nathan Rajlich 13 0.48 % 20.00 Irakli Gozalishvili 14 0.48 % 20.00 Tim Caswell 15 0.46 % 19.00 Kris Kowal
  16. Populair • Webservers/Frameworks • IRC servers • Databases ◦ MySQL

    ◦ MongoDB ◦ CouchDB ◦ Redis • Message Queues ◦ ZeroMQ ◦ Rabbit MQ