# extrass

> Packed with some express utils

Latest version **2.0.2** (published 2023-09-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install extrass
pnpm add extrass
yarn add extrass
bun add extrass
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2023-09-26 |
| First published | 2023-05-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | NazmusSayad |
| Maintainers | nazmussayad |

## Links

- npm: https://www.npmjs.com/package/extrass
- Repository: https://github.com/NazmusSayad/express-master
- Homepage: https://github.com/NazmusSayad/express-master#readme
- Issues: https://github.com/NazmusSayad/express-master/issues
- npm.io page: https://npm.io/package/extrass

## Dependencies (1)

- [req-error](https://npm.io/package/req-error.md) ^2.0.1

## Recent versions

- 2.0.2 (latest) — 2023-09-26
- 2.0.1 — 2023-09-26
- 2.0.0 — 2023-09-14
- 1.0.19 — 2023-09-14
- 1.0.18 — 2023-09-11
- 1.0.17 — 2023-09-10
- 1.0.16 — 2023-09-10
- 1.0.15 — 2023-09-10
- 1.0.14 — 2023-08-25
- 1.0.13 — 2023-08-25
- 1.0.12 — 2023-08-25
- 1.0.11 — 2023-08-04
- 1.0.10 — 2023-08-04
- 1.0.9 — 2023-08-04
- 1.0.8 — 2023-08-04
- … 11 more at https://npm.io/package/extrass/versions

## README

# extrass

Packed with some express utils

<a href="https://npmjs.com/package/extrass">
  <img src="https://img.shields.io/npm/v/extrass" alt="npm package"> 
</a>

## Installation

- with npm

```shell
npm i extrass
```

- with yarn

```shell
yarn add extrass
```

- with pnpm

```shell
pnpm add extrass
```

## Usage

`app.js`

```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(/* ... */)
```

```js
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'](https://www.npmjs.com/package/req-error)

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