npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mini-tools

v1.12.2

Published

mini tools for express and others

Downloads

201

Readme

mini-tools

mini tools for express and others

stable npm-version downloads build windows coverage outdated-deps

language: English also available in: Spanish

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. If the error object has setted the property

  • code: is displayed before the message
  • status: is sended in the header (otherwise "400" is sended)
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, opts)

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

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 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

serveText(anyText,contentTypeText)

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".

serveJson(object)

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.

serveYaml(object)

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).

readConfig(list, opts)

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

  • whenNotExist:'ignore'
  • whenNotExist:'fail'

License

MIT