This file contains 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 express = require('express'); | |
var app = express(); | |
app.use(express.static(__dirname)); | |
app.get('/data.json', function(req, res) { | |
res.set('Cache-Control', 'public, max-age=20'); | |
res.send({ value : Math.random() }); | |
}); |
This file contains 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
// include this middleware before any middleware/routes that is suspected of triggering the error | |
app.use(function(req, res, next) { | |
res.on('header', function() { | |
console.trace('HEADERS GOING TO BE WRITTEN'); | |
}); | |
next(); | |
}); |
This file contains 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> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect(''); | |
socket.on('connect', function() { | |
console.log('connect'); | |
socket.emit('start'); | |
}); |
This file contains 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 app = require('express')() | |
, server = require('http').createServer(app) | |
, io = require('socket.io').listen(server); | |
server.listen(3012); | |
app.get('/', function (req, res) { | |
res.sendfile(__dirname + '/index.html'); | |
}); |
This file contains 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 fact = function(n) { if (n === 0) return 1; return n * fact(n - 1); }; | |
var start = process.hrtime(); | |
fact(150); | |
var diff = process.hrtime(start); | |
console.log('fact(150) took %d nanoseconds', diff[0] * 1e9 + diff[1]); | |
var child_process = require('child_process'); | |
var start = process.hrtime(); |
This file contains 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 express = require('express'); | |
var app = express(); | |
app.use(express.cookieParser()); | |
app.use(express.bodyParser()); | |
app.set('view engine', 'jade'); | |
var cookieMiddleware = function (req, res, next) { | |
var cookie = req.cookies.user; | |
if (cookie === undefined) |
This file contains 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 http = require('http'); | |
http.createServer(function(request,response) { | |
response.writeHead(200,{"Content-Type":"text/html"}); | |
response.write("<h1>Hello, Web!</h1>"); | |
setTimeout(function() { | |
response.end(JSON.stringify({ foo : 'bar' })); | |
}, 1000); | |
}).listen(8888); |
This file contains 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 domain = require('domain'); | |
var fs = require('fs'); | |
var mainDomain = domain.create(); | |
mainDomain.run(function() { | |
fs.readFile('foo', 'utf8', mainDomain.intercept(function(data) { | |
console.log(data); | |
})); | |
}); |
This file contains 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 express = require('express'); | |
var app = express(); | |
app.use(express.static(__dirname)); | |
app.get('/search', function(req, res){ | |
res.send({ hello : 'world' }); | |
}); | |
app.listen(3012); |
This file contains 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 validate_email(email) { | |
var re = new RegExp( | |
"^([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c" + | |
"\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22" + | |
"\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)(\\x2e" + | |
"([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e" + | |
"\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-" + | |
"\\xff]|\\x5c[\\x00-\\x7f])*\\x22))*\\x40([^\\x00-\\x20\\x22" + | |
"\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]" + | |
"+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x5d)" + |