A dream will always triumph over reality, once it is given the chance. Stanislaw Lem
Every I/O call must take a callback, whether it is to retrieve information from disk, network or another process
HTTP, DNS, TLS
Does not remove functionality present at the POSIX layer. For example, support half-closed TCP connections.
Never force the buffering of data
fs.readFile('/etc/passwd', function(err, data) { console.log(data); });
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8081); console.log('Server running at port 8081');
var http = require('http'); http.createServer(function (req, res) { var path = url.parse(req.url).pathname; var hello = {message: "Hello, world"}; switch (path) { case '/json': res.writeHead(200, {'Content-Type': 'application/json; charset=UTF-8'}); res.end(JSON.stringify(hello)); break; default: res.writeHead(404, {'Content-Type': 'text/html; charset=UTF-8'}); res.end('Sorry, we cannot find that!'); } }).listen(8081);
var express = require('express'); var app = express(); app.get('/', function(req, res) { res.send('Hello World'); }); app.listen(8081);
var express = require('express'); var app = express(); var hello = {message: "Hello, world"}; app.get('/json', function(req, res) { res.json(hello); }); app.all('*', function(req, res) { res.send(404, 'Sorry, we cannot find that!'); }); app.listen(8081);
session, CSRF, basicAuth, vhost, static content, custom
var express = require('express'), routes = require('./routes'), api = require('./routes/api'); var app = express(); app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.static(__dirname + '/public')); app.use(app.router); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); });
app.get('/', routes.index); // res.render('index'); app.get('/posts', api.posts); app.get('/posts/:id', api.post); //var id = req.params.id; app.post('/posts', api.addPost); //res.json(req.body); app.put('/posts/:id', api.editPost); app.delete('/posts/:id', api.deletePost); app.get('*', routes.index); app.listen(3000, function(){ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); });
db.articles.find({'comments.0.by':'becevka'})
var mongo = require('mongoskin'); var db = mongo.db('localhost:27017/test?auto_reconnect');
db.bind('posts', { removeTagWith : function (tag, fn) { this.remove({tags:tag}, fn); } }); db.posts.removeTagWith('delete', function (err, replies) { //do something });
Tim (Berners-Lee) bawled me out in the summer of '93 for adding images to the thing Marc Andreesen, Mosaic
<label>Here is your value:</label> <input type="text" name="value"/> <span>Here is double: {{value * 2}}</span>
<span id="yourName"></span> document.getElementById('yourName')[0].text = 'bob';
<span>{{yourName}}</span> var yourName = 'bob';
<div ng-controller="AlbumCtrl"> <ul> <li ng-repeat="image in images"> <img ng-src="{{image.thumbnail}}" alt="{{image.description}}"> </li> </ul> </div>
function AlbumCtrl($scope) { scope.images = [ {"thumbnail":"img/image_01.png", "description":"Image 01 description"}, {"thumbnail":"img/image_02.png", "description":"Image 02 description"}, {"thumbnail":"img/image_03.png", "description":"Image 03 description"}, {"thumbnail":"img/image_04.png", "description":"Image 04 description"}, {"thumbnail":"img/image_05.png", "description":"Image 05 description"} ]; }
function EditCtrl($scope, $location, $routeParams, User) { // Something clever here... }
<div class="container"> <div class="inner"> <ul> <li>Item <div class="subsection">item 2</div> </li> </ul> </div> </div>
<dropdown> <item>Item 1 <subitem>Item 2</subitem> </item> </dropdown>
<td>{{name|uppercase}}</td>
app.factory('User', function ($resource) { var User = $resource('/users/:_id', {}, { update: { method: 'PUT', params: {_id: "@_id" }} }); return User; });
app.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/login', { templateUrl: 'partials/login', controller: LoginCtrl }); }]);
<html ng-app='myApp'> <head> <title>Your Shopping Cart</title> </head> <body ng-controller='CartController'> <h1>Your Order</h1> <div ng-repeat='item in items'> <span>{{item.title}}</span> <input ng-model='item.quantity'> <span>{{item.price | currency}}</span> <span>{{item.price * item.quantity | currency}}</span> <button ng-click="remove($index)">Remove</button> </div> <script src="angular.js"> </script> <script> angular.module("myApp", []); function CartController($scope) { $scope.items = [ {title: 'Paint pots', quantity: 8, price: 3.95}, {title: 'Polka dots', quantity: 17, price: 12.95}, {title: 'Pebbles', quantity: 5, price: 6.95} ]; $scope.remove = function(index) { $scope.items.splice(index, 1); } } </script> </body> </html>
$ npm install -g amigo amigo todo
/