Node.js

2,557 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,557
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
30
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Node.js

    1. 1. mat@schaffer.me@matschafferhttp://github.com/matschafferhttp://mashion.netdidn’t write node.js
    2. 2. I’m not Ryan Dahlbut he’ll be atPhilly ETE
    3. 3. What is ?
    4. 4. ?
    5. 5. But why?
    6. 6. • Larger developer pool• Write-once business logic• Server-side fallbacks but also....
    7. 7. Asynchonous vs.Synchronous
    8. 8. // Asynchronous$.get(ajax/test.html,      function(data) {        $(.result).html(data);        alert(Async!);      });
    9. 9. // Synchronousvar data = $.get(ajax/test.html);
    10. 10. Evented (async) vs.Threaded (sync)
    11. 11. Getting it (source)git clone git://github.com/ry/node.gitcd node./configure --prefix=/usr/localmakemake install || sudo make install
    12. 12. Getting it (packaged) brew install node port install nodejs
    13. 13. Node Basics
    14. 14. console.log(hello world);$ node helloworld.jshello world
    15. 15. var fs = require(fs);fs.writeFile(hello.txt, hello world, function (err, fd) {   if (err) throw err;   console.log(done.); });$ node helloworld.jsdone.$ cat hello.txthello world
    16. 16. var fs = require(fs);• require(‘mylib’) ≈ <script src=”mylib.js”>• require returns the library’s exports
    17. 17. module.exports = {  writeFile: function(path, data, callback) {...},  readFile: function(path, callback) {...}};
    18. 18. A web server
    19. 19. var http = require(http);http.createServer(function (req, res) {  res.writeHead(200,    {Content-Type: text/plain});  res.end("Hello worldn");}).listen(8000);
    20. 20. Working with Evented Libraries
    21. 21. not this...things.each(function(thing) {  doStuffWith(i);});
    22. 22. this!things.each(function(thing, next) {  doStuffWith(i, next);});
    23. 23. Get packages with npm npm install express
    24. 24. Testing Options• Built in assert library• Jasmine• Expresso• Vows
    25. 25. Cool Node.js Projects
    26. 26. node-inspector
    27. 27. Expressvar express = require(express),    app = express.createServer();app.get(/, function(req, res){    res.send(Hello World);});app.listen(3000);
    28. 28. Socket.IO Real time client/server messaging// socket.iovar socket = io.listen(server);socket.on(connection, function(client){  // new client is here!  client.on(message, function(){ … })  client.on(disconnect, function(){ … })});
    29. 29. Massively multiplayer scrabble!!1!1!!
    30. 30. App in a browser!!
    31. 31. Analytics pr0n!11!!!!1

    ×