dmbexpress

Additional help for API developing with node + express.

Usage no npm install needed!

<script type="module">
  import dmbexpress from 'https://cdn.skypack.dev/dmbexpress';
</script>

README

dmbexpress

Additional help for API developing with node + express.

What you can do with dmbexpress

This module is only a help for making frequent coding tasks more easy.

  • Easy output for express API. Don't worry. Send to output function anything: text, objects or even error code (it handles node and mongoose errors the best it can, with minimal action). Output is automatically formatted to json.
  • Easy error handling in your functions. Don't throw an exception if it's not exceptional! Integrated with output function, so you can send an error text and the corresponding state page code without throw errors.
  • Objects handling functions. No need for extra modules if you only want to pick, filter or map an object like you do with arrays, and new features like update an object with other object data using modifiers. More functions coming soon.

Note from the author

When I first created dmbexpress, I was thinking only in my very own needs for node backend API with express. Anyway, it grew up, so more functions where added. And it started to loose sense. So I decided to separate dmbexpress into two different modules: dmboutput and dmbobjects.

Because I wanted to keep dmbexpress running for people who were already using it in their projects, but did not want to have to do double maintenance of the same functions, I modified dmbexpress to be a bridge between the two new modules.

Please, if you want to use the dmbexpress functions, it is preferable that you refer directly to the dmbobjects and dmboutput modules.

Install

npm i dmbexpress -s

Import

const dmb = require('dmbexpress');

Functions overview

Output handling:

Please, for a better perfomance, if you want to use the output handling functions of dmbexpress, refer to dmboutput.

dmb.output

Easy output of what you could want as json API. Don't worry it's string, object, redirection or even an error object. The function will find the best way to output to client.

Error handling:

Please, for a better perfomance, if you want to use the error handling functions of dmbexpress (and many others), refer to dmboutput.

dmb.error

Handle errors and exceptions and output them easy. Full ready for working with dmb.output function, so you can aggregate an code status to the error message.

dmb.isError

Tells you if the returned object is an error (both native error and dmbexpress error).

Objects handling:

Please, for a better perfomance, if you want to use the object handling functions of dmbexpress, refer to dmbobjects.

dmb.copy

Returns a independent copy of one object.

dmb.pick

Obtain a new object with only the properties you want.

dmb.filter

Obtain a new object with only the properties you select by a callback.

dmb.map

Obtain a new object with the values modified by your own callback.

dmb.update

Update an object with the data of another object using different modifiers or even your own callback.

dmb.fusion

Obtain a new object with the data of another object using different modifiers or even your own callback applied over all the resulting object properties.

dmb.validate

Validate if an object matches a validation scheme defined by you.