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 domain = require('domain'); | |
var events = require('events'); | |
var d = domain.create(); | |
d.on('error', function(e){ | |
console.error('d:', e.message); | |
}); | |
d.run(function(){ | |
var ee = new events.EventEmitter(); | |
ee.emit('error', new Error('emitted error')); | |
}); |
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 domain = require('domain'); | |
var d = domain.create(); | |
d.on('error', function(e){ | |
console.error('d:', e.message); | |
}); | |
d.run(function(){ | |
throw new Error('throwed error'); | |
}); |
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 fs = require('fs'); | |
process.on('uncaughtException', function(e){ | |
console.log('uncaughtException:', e.message); | |
}); | |
try{ | |
fs.readFile('non-exists.txt', 'utf-8', function(err, data){ | |
if(err) throw err; | |
console.log('data:', data); | |
}); | |
}catch(e){ |
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 http = require('http'); | |
var port = 1337; | |
var obj = {}; | |
var server = http.createServer(function(req, res){ | |
var remoteAddress = req.connection.remoteAddress; | |
var header = {'Connection' : 'close', 'Content-Length' : 0}; | |
var key = req.url; | |
switch (req.method){ | |
case 'POST': | |
if(obj[key]){ |
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 http = require('http'); | |
options = { host: '192.168.11.14', | |
port: 1337, | |
auth: 'alice:alicepass'}; | |
var req = http.request(options, function(res){ | |
var data = ''; | |
res.on('data', function(chunk){ | |
data += chunk; | |
}); | |
res.on('end', function(){ |
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 http = require('http'); | |
var host = '192.168.11.14'; | |
var port = 1337; | |
var htpasswd = {'alice' : 'alicepass'}; | |
var server = http.createServer(function(req, res){ | |
function showAuthContent(res, username, password){ | |
if(username in htpasswd && htpasswd[username] === password){ | |
res.writeHead(200, {'Content-Type' : 'text/plain' }); | |
res.end('Hello Authed World\n'); | |
}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 http = require('http'); | |
var options = { host: 'localhost', | |
port: 1337, | |
path: '/', | |
method: 'POST'}; | |
var req = http.request(options, function(res){ | |
var data = ''; | |
res.on('data', function(chunk){ | |
data += chunk; | |
}); |
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 http = require('http'); | |
var server = http.createServer(); | |
var port = 1337; | |
server.on('request', function(req, res){ | |
var data = ''; | |
req.on('data', function(chunk){ | |
data += chunk; | |
}); | |
req.on('end', function(){ |
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 readline = require('readline'); | |
var options = {}; | |
options.host = process.argv[2]; | |
options.port = process.argv[3]; | |
var client = net.connect(options); | |
client.on('error', function(e){ |
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 readline = require('readline'); | |
var server = net.createServer(); | |
server.maxConnections = 3; | |
function Client(socket){ | |
this.socket = socket; | |
} |