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

nowjs #TechLunch

nowjs #TechLunch

2011/08/31(水) @ Livesense TechLunch
発表者:桂 大介

Livesense Inc.

April 23, 2014
Tweet

More Decks by Livesense Inc.

Other Decks in Technology

Transcript

  1. C10K Problem http://en.wikipedia.org/wiki/C10k_problem The C10k problem is a limitation that

    most web servers currently have, which limits the web server to being able to handle a maximum of about ten thousand simultaneous connections.
  2. Servers which address the problem • Nginx • Lighttpd •

    Tornado@python • EventMachine@ruby • And..
  3. node.js Evented Server-side Javascript Good at handling lots of different

    kinds of I/O at the same time. Achieves this by all making network I/O nonblocking and all file I/O asynchronous. (Almost all.)
  4. node.js Node's goal is to provide an easy way to

    build scalable network programs.
  5. hello world 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");
  6. npm npm is a package manager for node. You can

    use it to install and publish your node programs. It manages dependencies and does other cool stuff.
  7. express • Robust routing • Redirection helpers • Dynamic view

    helpers • Application level view options • Content negotiation • Application mounting • Focus on high performance • View rendering and partials support • Environment based configuration • Session based flash notifications • Built on Connect • Executable for generating applications quickly • High test coverage
  8. hello world var express = require('express'); var app = express.createServer();

    app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000);
  9. Client-side source $(document).ready(function(){ now.receiveMessage = function(name, message){ $("#messages").append("<br>" + name

    + ": " + message); } $("#send-button").click(function(){ now.distributeMessage($("#text-input").val()); $("#text-input").val(""); }); now.name = prompt("What's your name?", ""); });
  10. Server-side source var html = require('fs').readFileSync(__dirname+'/helloworld.html'); var server = require('http').createServer(function(req,

    res){ res.end(html); }); server.listen(process.env.PORT); var nowjs = require("now"); var everyone = nowjs.initialize(server); everyone.now.distributeMessage = function(message){ everyone.now.receiveMessage(this.now.name, message); };