2.0.2 • Published 8 months ago

extrass v2.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

extrass

Packed with some express utils

Installation

  • with npm
npm i extrass
  • with yarn
yarn add extrass
  • with pnpm
pnpm add extrass

Usage

app.js

const express = require('express')
const extrass = require('extrass')
/* After importing this, a class named "ReqError" will be global
and everything those are exported from req-error package is also exported here
check https://www.npmjs.com/package/req-error for that
*/

const app = express()

// ..... Your routes

extrass(app)
app.listen(/* ... */)
const express = require('express')
const { createExtrass } = require('extrass')
/* After importing this, a class named "ReqError" will be global
and everything those are exported from req-error package is also exported here
check https://www.npmjs.com/package/req-error for that
*/

const app = express()

const extrass = createExtrass({
  // If any strings provided that will be the route for pinging the server
  ping: '/ping',

  // This will be the res.success method, If you provide here. don't forget to declear it's types manually
  successMethod: function (data) {
    const resData = { status: 'success', data }
    this.json(resData)
    return resData
  },

  // This will be the message
  errorMessages: {
    statusCode: 400,
    notFound: ["Oops, looks like you're lost in space!", 404],
    exceptions: ['Something went very wrong!', 500],
    JSONParse: ['Invalid data recieved', 400],
    jwtExpire: ['Your token is no longer valid', 401],
    jwtInvalid: ['Login credentials are invalid', 401],
    mongoCast: ['Invalid input for `{$}`', 400],
    mongoObjParam: ['Invalid input for `{$}`', 400],
  },

  // Format the Error
  formatError: (error, statusCode) => {
    // If NODE_ENV === 'development'
    // error = {
    //   message: 'Invalid auth token',
    //   error: Error,
    //   stack: Error.stack,
    // }
    //
    // Else:
    // error = {
    //   message: 'Invalid auth token',
    // }

    return {
      status: statusCode < 500 ? 'fail' : 'error',
      ...error,
    }
  },
})

extrass.handle(app)
app.listen(/* ... */)

Must watch:

Checkout 'req-error'

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

8 months ago

2.0.2

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.0.15

8 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago

0.0.0

12 months ago