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> | |
<title>socket.io echo</title> | |
<style> | |
body { font: 120% 'Open Sans', sans-serif; padding: 1em 2em 0; } | |
input, button { font-size: 110%; padding: 0.4em} | |
</style> | |
</head> |
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 firstFunc(somevalue, callback) { | |
// pass the values, error as null (no possibility of error here) and the value is the new string | |
// this is the normal node convention | |
callback(null, somevalue += ' ok'); | |
} | |
// call the function with the string and an anon function that get's the values from the callback | |
firstFunc('this should be', function (error, callbackvalue) { | |
if (!error) { | |
// if the callback didn't pass an error, then things should be ok |
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 httprequest = require('request'); | |
var page = 1; | |
(function repeat() { | |
var req = httprequest("http://www.google.com", function (error, response, body) { | |
console.log(response.statusCode); | |
if (page < 2) { | |
page += 1; | |
repeat(); | |
} else { | |
console.log('done'); |
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
module.exports = function (port, path) { | |
"use strict"; | |
var http = require('http'), | |
express = require('express'), | |
app = express(), | |
server = http.createServer(app), | |
path = path || __dirname, | |
port = port || 8555; | |
app.use(express.static(path)); |
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 net = require('net'), | |
bro = '....Cool story bro.\r\n', | |
Stream = require('stream'), | |
stream = new Stream, | |
server = net.createServer(function (socket) { | |
socket.setEncoding('utf8'); | |
socket.pipe(stream).pipe(socket); | |
}); | |
stream.readable = true; |
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 httpProxy = require('http-proxy'), | |
httpOptions = { | |
router: { | |
'someservername' : '127.0.0.1:3001', | |
'otherservername' : '127.0.0.1:3002', | |
'/*' : '127.0.0.1:3000' | |
} | |
}, | |
httpProxyServer = httpProxy.createServer(httpOptions); |
NewerOlder