
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
mini-tools
Advanced tools
mini tools for express and others
$ npm install mini-tools
Have some mini tools for express and others
Returns a function that sends a error message to de front-end. If the error object has setted the property
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.
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 opts is boolean it will be the any option.
If any==true
it serves files adding .jade to req.path; and
if there is no jade file it call next()
.
If any==false
it serves that specific file.
Others options in opts are pased to pug.render
function.
Note: for use serveJade you must include "pug"
in package.json
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 serves files adding .jade to req.path; and
if there is 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
var express = require('express');
var app = express();
app.use('/about',MiniTools.serveText('<h1>This app</h1>','html'));
app.use('/is-up-service',MiniTools.serveText('Yes.'));
Returns an express middleware to serve pain text. Optionaly you can pass "content type".
var express = require('express');
var app = express();
var config = {devel:false, title: "title"};
app.use('/config',MiniTools.serveJson(config));
Returns an express middleware to serve an object in JSON format.
var express = require('express');
var app = express();
var config = {devel:false, title: "title"};
app.use('/config',MiniTools.serveYaml(config));
Returns an express middleware to serve an object in yaml format (using js-yaml).
MiniTools.readConfig(
[
{production: true},
'package.json',
'other-configs.yml',
'more-configs',
],
{whenNotExist:'ignore'}
).then(function(config){
console.log(config);
});
Reads the chain of configuration merging with best-globals.changing.
If the list element is a fileName ending with .json .yaml o .yml, it reads and parse, if doesn't have extension it search first, if it is a plain object it uses directly.
options
FAQs
mini tools for express and others
The npm package mini-tools receives a total of 35 weekly downloads. As such, mini-tools popularity was classified as not popular.
We found that mini-tools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.