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
http.createServer(function (req, resp) { | |
sys.puts('http request'); | |
multipart.parse(req).addCallback(function(httpParams) { | |
sys.puts('multipart.parse'); | |
processRequest( req , resp , httpParams ); | |
}).addErrback(function(){ | |
sys.puts('multipart request error'); | |
resp.sendHeader(200,{'Content-Type':'text/html'}); |
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 sys = require('sys'), | |
tcp = require('tcp'), | |
debug = require('./debug'); | |
var email = {}; | |
email.send = function(){ | |
var connection = tcp.createConnection('25', host="127.0.0.1"); | |
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 posix = require('posix'), | |
debug = require("./debug"), | |
sys = require('sys'); | |
var application = {}; | |
//location to application state data | |
application.dataPath = '/var/www/foobar.com/server/data.json'; | |
application.data = {}; |
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
application.end = function(){ | |
sys.puts('application end'); | |
application.saveState(true); | |
}; | |
application.saveState = function(shutdown){ | |
sys.puts('application saveState'); | |
//dump data.json into application state | |
var mode = 0444; | |
var x = posix.open(application.dataPath ,process.O_RDWR|process.O_TRUNC,0444).addCallback(function(fd){ |
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
posix.cat(path, 'binary').addCallback(function (content) { | |
debug.log('file found : ' + path ); | |
req.setBodyEncoding('binary'); | |
resp.sendHeader(200,{'Content-Type':mime.mime(path)}); | |
resp.sendBody(content); | |
resp.finish(); | |
}) |
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
http.createServer(function (req, resp) { | |
var httpParams = {}; | |
multipart.parse(req).addCallback(function() { | |
sys.puts('multipart.parse'); | |
processRequest( req , resp , httpParams ); | |
}).addErrback(function(err){ | |
resp.sendHeader(200,{'Content-Type':'text/html'}); | |
resp.sendBody('500 error in response :' + JSON.stringify(err)); | |
resp.finish(); | |
}); |
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 httpParams = {}; | |
req.uri = url.parse(req.url); | |
process.mixin(true, httpParams, req.uri.params); |
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 httpParams = {}; | |
req.uri = url.parse(req.url); | |
if(typeof req.uri.query == 'undefined'){req.uri.query = '';} | |
req.uri.params = querystring.parse(req.uri.query); | |
req.uri.path = req.uri.pathname; | |
process.mixin(true, httpParams, req.uri.params); | |
multipart.parse(req).addCallback(function(parts) { | |
process.mixin(true, httpParams, parts); | |
processRequest( req , resp , httpParams ); |
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
http.createServer(function (req, resp) { | |
req.body = ''; | |
req.addListener('data',function(chunk){ | |
req.body += chunk | |
}) | |
req.addListener('end', function(){ | |
var httpParams = {}; |
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
// simple variable replacement using {{}} and Mustache.to_html() | |
var str = Mustache.to_html('i like hats that are {{color}}', | |
{ | |
color : "blue" | |
} | |
); | |
console.log(str); // i like hats that are red | |
// replacing multiple variables | |
var str = Mustache.to_html('i like {{thing}} that are {{color}}', |