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

node

nctunba
May 02, 2012
49k

 node

nctunba

May 02, 2012
Tweet

Transcript

  1. go fetch some file do nothing and wait ... wait

    ... wait ... got the file! assign it to foobar Meanwhile result = readFile('foo') foobar = result
  2. go fetch some file wait ... wait ... wait ...

    got the file! assign it to foobar Meanwhile readFile('foo', function (result) { foobar = result })
  3. go fetch some file 'Hello!!' wait ... wait ... got

    the file! assign it to foobar Difference readFile('foo', function (result) { foobar = result }) Print('hello!!')
  4. “Tell me when you're done, I have something else to

    do” Event loop Evented I/O Non-blocking I/O
  5. From 1 to 10000 or even more Ability to scale

    Evented I/O scales well! Scalability
  6. Node.js runs in a single process How to take advantage

    of multi-core? Simple, run more Node instance! Single Threaded
  7. var http = require('http'); http.Server(function (req, res) { res.writeHead(200, {'Content-Type':

    'text/plain'}); res.end('Hello World\n'); }).listen(3000); HTTP server
  8. var net = require('net'); var server = net.Server(function (socket) {

    socket.write('Echo server\r\n'); socket.pipe(socket); }).listen(1337); TCP server