Skip to content

Instantly share code, notes, and snippets.

@chickencoder
Created June 28, 2014 20:51
Show Gist options
  • Save chickencoder/f7135b3c66c4a2ce7588 to your computer and use it in GitHub Desktop.
Save chickencoder/f7135b3c66c4a2ce7588 to your computer and use it in GitHub Desktop.
A simple module of useful methods for use when creating Web Applications in pure Node.
/*
Green Tea ~ A node-non-web-framework.
Green Tea is a collection of tools to
make writing web applications in node
a whole lot easier!
Created By Jesse Sibley.
On the 28th June 2014.
*/
// Require Some Node Modules
var http = require('http');
var fs = require('fs');
// Give Green Tea Welcome
console.log("Green Tea 0.1");
var mug =
[" ( (",
" ) )",
" ........",
" | |]",
" \\ /",
" `----'"].join('\n')
console.log(mug);
// Render Function
exports.render = function(response, template){
response.writeHead(200, {'Content-Type' : 'text/html'});
response.end(template);
}
// HTML Templaing Function
exports.template = function(response, filename){
fs.readFile(filename, 'utf8', function(err, data){
if (err) {
return console.log(err)
}
response.writeHead(200, {'Content-Type' : 'text/html'});
response.end(data);
});
}
// Mapping Function
exports.map = function(request, regex, callback){
var url = request.url;
var method = request.method;
var result = url.match(regex);
if(result){
console.log("[" + method + "] Request: " + "'" + url + "'")
callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment