mini-tools
mini tools for express and others

language:
also available in:

Install
$ npm install mini-tools
Main goal
Have some mini tools for express and others
API
serveErr(req, res [, next])
Returns a function that sends a error message to de front-end.
app.post('/insert' , function(req,res){
if(duplicate){
serveErr(req,res)(new Error("Duplicate name. Can't insert"));
return;
}
It is promise friendly
app.use('/tools', function(req,res,next){
.then(function(){
if(not_in_this_middleware){
throw new Error("next");
}
}).catch(serveErr(req,res,next));
catch expects a function that receive an error.
serveErr returns that function.
When err is Error("next") serveErr calls next and does not send any result to de front-end;
otherwise it sends a 400 error with the message and stack.
serveJade(path, any)
var express = require('express');
var app = express();
app.use('/',MiniTools.serveJade('./static',true));
app.use('/main',MiniTools.serveJade('./static/index.jade',false));
Returns an express middleware to serve jade files.
If any==true
it serve files adding .jade to req.path; and
if there no jade file it call next()
.
If any==false
it serves that specific file.
Note: for use serveJade you must include jade in package.json
serveStylus(path, any)
var express = require('express');
var app = express();
app.use('/',MiniTools.serveStylus('./static',true));
app.use('/site.css',MiniTools.serveStylus('./static/index.styl',false));
Returns an express middleware to serve jade files.
If any==true
it serve files adding .jade to req.path; and
if there no jade file it call next()
.
If any==false
it serves that specific file.
Note: for use serveStylus you must include stylus in package.json
It is promise friendly
app.use('/tools', function(req,res,next){
.then(function(){
if(not_in_this_middleware){
throw new Error("next");
}
}).catch(serveErr(req,res,next));
catch expects a function that receive an error.
serveErr returns that function.
When err is Error("next") serveErr calls next and does not send any result to de front-end;
otherwise it sends a 400 error with the message and stack.
License
MIT
.............................