Your SlideShare is downloading. ×
  • Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

An overview of node.js and quick reference for some of the most useful tools in the ecosystem.

An overview of node.js and quick reference for some of the most useful tools in the ecosystem.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,553
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
46
Comments
0
Likes
10

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • how many of you know what node is? how many have used it? how many of you have production apps running on it?







  • node.js is new, and there is still a lot of re-inventing the wheel going on
    many packages, some better than others
    everything is being actively developed, for better and worse






  • node is very low-level
    express is slightly higher-level, sinatra, not rails
    includes things like routing and logging
    and tons of plugins via the connect middleware that it’s built on

  • cross browser real time messaging









Transcript

  • 1. The Last 10% lessons from building node.js apps
  • 2. I node.js http://nodeknockout.com http://lazeroids.com http://monitaur.net
  • 3. I node.js / disclamer “This is the website code for http://nodeknockout.com. It was written before a lot of the libraries it uses (e.g. express, Connect, even npm) were mature. So, it's pretty gross. If you want a lesson in how to get things done, but as quickly and hackily as possible, you're in the right place.”
  • 4. node.js • fast • memory-efficient • server-side javascript
  • 5. node / fast node 822 nginx 708 thin 85 mongrel 4 0 225 450 675 900 reqs/sec * contrived, old benchmark (but right order of magnitude)
  • 6. node / memory-efficient apache - threaded nginx - event loop (like node) http://blog.webfaction.com/a-little-holiday-present
  • 7. node / server-side javascript var http = require('http'); http.createServer(function(req, res) { res.writeHead(200); res.end('Hello World'); }).listen(8124); console.log("running on port 8124...");
  • 8. Modules https://github.com/ry/node/wiki/modules ~500 modules
  • 9. modules / choice 88 “web framework” modules
  • 10. Package Mgmt curl http://npmjs.org/install.sh | sh
  • 11. npm / commands Finding packages - npm ls > npm ls db Installing packages - npm install > npm install mongodb Using packages - require > var mongodb = require("mongodb");
  • 12. npm / package.json > cat package.json { "name": "last10", "version": "0.0.1", "dependencies": { "mongodb": ">=0.7.9", "express": ">=1.0.0rc", "socket.io": ">=0.5.3" }} > npm install .
  • 13. Debugging npm install node-inspector
  • 14. node-inspector / commands Start node-inspector > node-inspector & Run your server with debugging on > node --debug helloworld.js View node-inspector in WebKit > open "http://127.0.0.1:8080"
  • 15. node-inspector / example
  • 16. Web Serving npm install express
  • 17. express / example var express = require('express'), app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World!'); }); app.listen(8125);
  • 18. Web Sockets npm install socket.io
  • 19. socket.io / example / client <script src="/socket.io/socket.io.js"> </script><script> var ws = new io.Socket(); ws.send('hello, world!'); ws.on('message', function(msg) { document.body.innerHTML += msg; }); </script>
  • 20. socket.io / example / server var express = require('express'), app = express.createServer(), ws = require('socket.io').listen(app); ws.on('connection', function(client) { client.on('message', function(msg) { client.broadcast(msg); }); }); app.listen(8125);
  • 21. Database npm install mongodb
  • 22. mongodb / example var mongodb = require('mongodb'), Db = mongodb.Db, Server = mongodb.Server, server = new Server("127.0.0.1", 27017, {}), db = new Db('mydb', server), message = "hello, world!"; db.open(function() { db.collection('messages', function(e, messages) { messages.insert({ text: message, words: message.replace(/W/g, ' ').split(/s+/), created_at: new Date() }); }); });
  • 23. mongodb / commands insert msgs.insert({ text: 'hello world', words: ['hello', 'world'], created_at: new Date() }); count msgs.count(function(e, c) { console.log(c + ' msgs'); }); query msgs.find({ words: /hello/i }, { sort: 'created_at' }, function(e, res) { res.each(function(e, msg) { console.log(msg); }); });
  • 24. Deploying
  • 25. upstart / example cat <<END > /etc/init/node.conf description "node" start on startup stop on shutdown script exec NODE_ENV=production node /path/to/server.js >> /path/to/node.log 2>&1 end script END
  • 26. Troubleshooting #node.js on irc.freenode.net http://nodejs.org http://groups.google.com/group/nodejs
  • 27. Thanks! @gerad