Knotter is a micro framework to create web application
knotter module is a nodejs middleware/microframework to create websites.
I really love ExpressJS and Connect. But what I wanted to do was to implement a pseudo WSGI-like system. The main goal is to bundle some of my prefered modules in one place:
At this time, you need to do some operation manually:
cd /path/to/yor/working/directory npm install knotter
Then, you can implement your first appliction, create a "site.js" file:
/*** Create your class that inherits from knotter.Handler*/function Page1Handler =knotterHandlercallthis;utilinheritsPage1Handler knotterHandler;// define the route to respond (regexp)// It is important that "route" is declared in prototype'/page1';// Respond to "GET" requests// there you can get: this.sessions, this.response, this.request// and this.params.args (ordered from captured regexp if any)// and this.params.get (given by ?arg=value&arg2=value2...)//// you can write response with this.end("Text to send to client");// or render a template: this.render('path to template', context_object)thisend"Welcome on page 1 !";;var server = knotterServerhandlers : Page1Handler //list of handlers classes,statics :statics : 'staticdir'images : 'imgdir'// directories to be served statically, eg. /images/test.png serves imgdir/test.png// you can pass "address" option to set listening address// address : "0.0.0.0" to listen on every interfaces;serverserve; //default listen on 127.0.0.1:8000 (open 127.0.0.1:8000/page1 to check result)
in 0.0.2, knotter could implement swig template engine. But we removed this options to let user using its own prefered template engine. Knotter goals is not to be a "full framework" and should stay "lightwave"
Now template engines are managed by the "consolidate" module. We only tested "swig" as engine and it works as expected. To use swig:
var server = knotterServer//...engine: 'swig'templates: __dirname+"/templates"engineOptions:root: __dirname+'/templates'allowErrors: trueautoescape: falsetzOffset: getTimezoneOffsetcache: false;
Afterward, in handler, you can use:
//...// test.html should be in __dirname/templates directory// ctx is an object that handle some vars you can// use in templatethisrender'test.html' ctx;
We will prepare a framework based on knotter that will implement some module as:
At this time, I didn't found any "nice" way to setup a file uploader. "Nice" means:
I guess I will implement "formidable" module to manage forms... One more time, I'm open to discuss about.