# mini-tools

> mini tools for express and others

Latest version **1.13.14** (published 2026-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install mini-tools
pnpm add mini-tools
yarn add mini-tools
bun add mini-tools
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.13.14 |
| Published | 2026-10-24 |
| First published | 2015-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 20 |
| Dependencies | 6 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Codenautas |
| Maintainers | estefi-capece, tute |

## Links

- npm: https://www.npmjs.com/package/mini-tools
- Repository: https://github.com/codenautas/mini-tools
- Homepage: https://github.com/codenautas/mini-tools#readme
- Issues: https://github.com/codenautas/mini-tools/issues
- npm.io page: https://npm.io/package/mini-tools

## Dependencies (6)

- [pug](https://npm.io/package/pug.md) ^3.0.4
- [send](https://npm.io/package/send.md) ^1.2.1
- [stylus](https://npm.io/package/stylus.md) ^0.64.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^5.5.0
- [cast-error](https://npm.io/package/cast-error.md) ^0.1.7
- [best-globals](https://npm.io/package/best-globals.md) ^2.2.3

## Recent versions

- 1.13.14 (latest) — 2026-10-24
- 1.13.13 — 2026-10-22
- 1.13.12 — 2026-10-18
- 1.13.11 — 2026-10-13
- 1.13.10 — 2026-07-27
- 1.13.8 — 2026-07-26
- 1.13.7 — 2026-06-28
- 1.13.6 — 2026-06-22
- 1.13.5 — 2026-02-01
- 1.13.4 — 2025-06-24
- 1.13.3 — 2025-06-22
- 1.13.2 — 2024-12-21
- 1.13.1 — 2024-12-21
- 1.12.2 — 2024-09-22
- 1.12.1 — 2023-05-27
- … 57 more at https://npm.io/package/mini-tools/versions

## README

# mini-tools
mini tools for express and others


[![npm-version](https://img.shields.io/npm/v/mini-tools.svg)](https://npmjs.org/package/mini-tools)
[![downloads](https://img.shields.io/npm/dm/mini-tools.svg)](https://npmjs.org/package/mini-tools)
[![linux](https://github.com/codenautas/mini-tools/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/codenautas/mini-tools/actions/workflows/build-and-test.yml)
[![windows](https://ci.appveyor.com/api/projects/status/github/codenautas/mini-tools?svg=true)](https://ci.appveyor.com/project/codenautas/mini-tools)
[![coverage](https://img.shields.io/coveralls/codenautas/mini-tools/master.svg)](https://coveralls.io/r/codenautas/mini-tools)
[![sonar](https://sonarcloud.io/api/project_badges/measure?project=codenautas_mini-tools&metric=alert_status)](https://sonarcloud.io/summary/overall?id=codenautas_mini-tools)
[![qa-control](https://github.com/codenautas/mini-tools/actions/workflows/qa-control.yml/badge.svg)](https://github.com/codenautas/mini-tools/actions/workflows/qa-control.yml)


language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
also available in:
[![Spanish](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-es.png)](LEEME.md)

## Install

```sh
$ 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)


```js
app.post('/insert' , function(req,res){
  //...
  if(duplicate){
    serveErr(req,res)(new Error("Duplicate name. Can't insert"));
    return;
  }
  //...
```


It is promise friendly


```js
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)

```js
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)

```js
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)

```js
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)

```js
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)

```js
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](https:www.npmjs.com/package/js-yaml)).


### readConfig(list, opts)

```js
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](https://www.npmjs.com/package/best-globals#changingoriginalconfig-changes-options).

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](LICENSE)

---
_Source: https://npm.io/package/mini-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
