app.http.before.push(function(req, res){
app.log.info(req.url);
res.emit('next');
})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flatiron = require('flatiron'), | |
app = flatiron.app; | |
console.log('What\'s that in your hand? Look down,'); | |
app.use(require('./tickets')); | |
console.log('look up. I HAVE IT. It\'s ' + app.qty + ' TICKETS to ' + app.description + '!'); | |
console.log('Look again.'); | |
app.use(require('./diamonds')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toString (obj) { | |
function _toString (i) { | |
if (obj[i] === null) return 'null' | |
if (typeof obj[i] === 'undefined') return 'undefined' | |
if (obj[i].toString) return obj[i].toString() | |
else return '' | |
} | |
return _toString | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user = { | |
validateCredentials: function (username, password) { | |
return ( | |
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' } | |
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' } | |
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' } | |
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' } | |
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' } | |
: false | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vows = require('vows') | |
, request = require('request') | |
, assert = require('assert') | |
, httpMocks = require('node-mocks-http') | |
static = require('../../lib/node-static'); | |
var fileServer = new(static.Server)(__dirname + '/../fixtures', {}); | |
var suite = vows.describe('file-server.js'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
* This module can verify that packages installed during development are | |
* identical to those installed during deployment. The standard npm shrinkwrap | |
* only ensures that package versions are the same, but does not verify contents. | |
* This module checks the shasum of the package tarballs downloaded by npm during | |
* development and deployment to ensure they are the same. | |
* | |
* Usage: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>XKCD plots in d3</title> | |
<script src="http://d3js.org/d3.v2.min.js?2.10.0"></script> | |
<script src="xkcd.js"></script> | |
<style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = []; | |
a[Math.pow(2, 32) - 2] = "max index"; // highest non-expando indexed property | |
console.log(a.length === Math.pow(2, 32) - 1); // true | |
try { | |
a.push("whoa", "EVEN MOAR WHOA"); | |
} catch (e) { | |
console.log(e instanceof RangeError); // true | |
} |
"Occurrences in this domain are beyond the reach of exact prediction because of the variety of factors in operation, not because of any lack of order in nature." - Albert Einstein
Error handling in an asynchronous language works in a unique way and presents many challenges, some unexpected. This tutorial reviews the various error handling patterns available in node, and explains how domains can be used to improve it.
There are four main error handling patterns in node:
- Error return value