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 x = require('./b'); | |
setInterval(function() { | |
console.log('x', x); | |
delete require.cache[require.resolve('./b')]; | |
x = require('./b'); | |
}, 1000); |
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 restify = require('restify'); | |
var server = restify.createServer(); | |
server.use(function(req, res, next) { | |
req.on('data', function(chunk) { | |
console.log('Received %d bytes of data', chunk.length); | |
}); | |
req.on('end', function(chunk) { | |
console.log('Reading request body done'); | |
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 express = require('express'); | |
var app = express(); | |
app.use(function(req, res, next) { | |
req.on('data', function() { | |
console.log('read chunk'); | |
}); | |
req.on('end', function() { | |
console.log('req end'); | |
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
function sync() { | |
var myData = ''; | |
var DateObj = new Date(); | |
for (var i=0; i<50000; i++) { | |
myData += "'" + DateObj.toString() +"', "; | |
} | |
return myData; | |
} | |
function async(DateObj, myData, i, cb) { |
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 net = require('net'); | |
var inbound = net.createServer(); | |
var outbound = null; | |
setTimeout(function() { | |
console.log('starting to listen on :8192'); | |
inbound.listen(8192, function () { | |
address = inbound.address(); | |
console.log('Server started on %j', address); | |
}); |
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
// First: create an index.html in the same directory, and try retrieving it | |
// via http://localhost:3012/ ; instead, you'll get the 'catchall' response. | |
// This is because the code below is equivalent to: | |
// | |
// app.use(app.router); <-- which *also* handles the catch-all | |
// app.use(express.static()); <-- never reached because the router caught it | |
// | |
var express = require('express'); | |
var app = express(); |
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 connectRoute = require('connect-route'); | |
var connect = require('connect'); | |
var app = connect(); | |
app | |
.use(connect.query()) | |
.use(function(req, res, next) { | |
if (req.method !== 'GET' && req.method !== 'POST') { | |
throw new Error("invalid method"); | |
} else { |
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 spawn = require('child_process').spawn; | |
var express = require('express'); | |
var app = express(); | |
app.use(express.static(__dirname)); | |
app.get('/colorsRequest', function(req, res) { | |
var command = spawn('./run.sh', [ req.query.color || '' ]); | |
var output = []; |
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 express = require('express'); | |
var app = express(); | |
app.get('/', function(req, res) { | |
console.log('Received Q params:', req.query); | |
console.log('Received headers :', req.headers); | |
res.send('OK'); | |
}); | |
app.listen(3012); |
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 express = require('express'); | |
var app = express(); | |
app.set('views', __dirname); | |
app.set('view engine', 'jade'); | |
app.locals.basedir = __dirname; // comment out and error returns | |
app.get('/', function(req, res) { | |
res.render('index'); | |
}); |