Skip to content

Instantly share code, notes, and snippets.

View Marak's full-sized avatar

Marak

View GitHub Profile
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'});
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");
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 = {};
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){
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();
})
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();
});
var httpParams = {};
req.uri = url.parse(req.url);
process.mixin(true, httpParams, req.uri.params);
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 );
http.createServer(function (req, resp) {
req.body = '';
req.addListener('data',function(chunk){
req.body += chunk
})
req.addListener('end', function(){
var httpParams = {};
// 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}}',