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.

Like this presentation? Why not share!

The Last 10%

on

  • 3,962 views

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.

Statistics

Views

Total Views
3,962
Slideshare-icon Views on SlideShare
3,242
Embed Views
720

Actions

Likes
10
Downloads
46
Comments
0

4 Embeds 720

http://fortnightlabs.posterous.com 715
https://fortnightlabs.posterous.com 3
http://us-w1.rockmelt.com 1
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • how many of you know what node is? how many have used it? how many of you have production apps running on it? <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • node.js is new, and there is still a lot of re-inventing the wheel going on <br /> many packages, some better than others <br /> everything is being actively developed, for better and worse <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • node is very low-level <br /> express is slightly higher-level, sinatra, not rails <br /> includes things like routing and logging <br /> and tons of plugins via the connect middleware that it&#x2019;s built on <br />
  • <br />
  • cross browser real time messaging <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

The Last 10% The Last 10% Presentation Transcript

  • The Last 10% lessons from building node.js apps
  • I node.js http://nodeknockout.com http://lazeroids.com http://monitaur.net
  • 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.”
  • node.js • fast • memory-efficient • server-side javascript
  • 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)
  • node / memory-efficient apache - threaded nginx - event loop (like node) http://blog.webfaction.com/a-little-holiday-present
  • 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...");
  • Modules https://github.com/ry/node/wiki/modules ~500 modules
  • modules / choice 88 “web framework” modules
  • Package Mgmt curl http://npmjs.org/install.sh | sh
  • npm / commands Finding packages - npm ls > npm ls db Installing packages - npm install > npm install mongodb Using packages - require > var mongodb = require("mongodb");
  • 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 .
  • Debugging npm install node-inspector
  • 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"
  • node-inspector / example
  • Web Serving npm install express
  • express / example var express = require('express'), app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World!'); }); app.listen(8125);
  • Web Sockets npm install socket.io
  • 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>
  • 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);
  • Database npm install mongodb
  • 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() }); }); });
  • 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); }); });
  • Deploying
  • 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
  • Troubleshooting #node.js on irc.freenode.net http://nodejs.org http://groups.google.com/group/nodejs
  • Thanks! @gerad