# navarrotech-express

> A standardized set of express utils wrapped into one

Latest version **1.0.30** (published 2024-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install navarrotech-express
pnpm add navarrotech-express
yarn add navarrotech-express
bun add navarrotech-express
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.30 |
| Published | 2024-06-11 |
| First published | 2023-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 16 |
| Unpacked size | 44.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Navarro |
| Maintainers | navarrotech |

## Links

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

## Dependencies (16)

- [yup](https://npm.io/package/yup.md) ^1.3.3
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [uuid](https://npm.io/package/uuid.md) ^9.0.1
- [helmet](https://npm.io/package/helmet.md) ^7.1.0
- [express](https://npm.io/package/express.md) ^4.18.2
- [typescript](https://npm.io/package/typescript.md) ^5.3.3
- [@types/cors](https://npm.io/package/@types/cors.md) ^2.8.17
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^9.0.7
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.6
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.21
- [express-session](https://npm.io/package/express-session.md) ^1.17.3
- [connect-pg-simple](https://npm.io/package/connect-pg-simple.md) ^9.0.1
- [express-rate-limit](https://npm.io/package/express-rate-limit.md) ^7.1.5
- [@types/cookie-parser](https://npm.io/package/@types/cookie-parser.md) ^1.4.6
- [@types/express-session](https://npm.io/package/@types/express-session.md) ^1.17.10
- [@types/connect-pg-simple](https://npm.io/package/@types/connect-pg-simple.md) ^7.0.3

## Recent versions

- 1.0.30 (latest) — 2024-06-11
- 1.0.29 — 2024-03-09
- 1.0.28 — 2024-03-09
- 1.0.27 — 2023-12-26
- 1.0.26 — 2023-12-24
- 1.0.25 — 2023-12-24

## README

# Navarrotech Express Utility
This NPM package provides a solution for setting up Express applications with enhanced features like CORS handling, session management, custom middleware, rate limiting, and more.

The idea is that creating a new project can be tedious, and this package can simplify the creation process.

## Features
- **CORS Configuration**: Enable or customize CORS settings.
- **Session Management**: Support for PostgreSQL, Redis, and in-memory session stores.
- **Custom Middleware Integration**: Easily integrate your custom middleware.
- **Rate Limiting**: Protect your application with configurable rate limits.
- **Helmet Security**: Use Helmet to set security-related HTTP headers.
- **Advanced Route Handling**: Define routes with validation and custom handling.
- **Static File Serving**: Serve static files with optional path customization.

## Installation
- To install the package, run the following command in your project directory:

```
npm install navarrotech-express
```

## Usage
Here's a basic example to create an Express application with the package:

```
import createApplication, { type CreateOptions } from 'navarrotech-express';

const options: CreateOptions = {
  cors: true, // Enable CORS
  // ... other options
};

const app = createApplication(options);

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});
```

## Options
The `CreateOptions` object accepts the following properties:

- **cors: boolean | string** - Enable CORS with true or specify a string for custom settings.
- **routes: Route[]** - Array of route objects to define application endpoints.
- **store: 'redis' | 'postgres' | 'memory' | Store** - Specify the session store type.
- **customMiddleware: any[]** - Array of custom middleware functions.
- **dontTrustProxy: boolean** - Set to true to disable trusting the proxy.
- **helmetOptions: Partial<HelmetOptions>** - Customize Helmet configuration.
- **rateLimitOptions: Partial<RateLimitOptions>** - Configure rate limiting.
- **sessionSecret: string** - Secret for signing the session ID.
- **sessionSettings: Partial<SessionOptions>** - Additional session configuration.
- **publicFolderPath: string** - Path to the folder for serving static files.
- **storeSettings: Partial<RedisStoreOptions> | Partial<PGStoreOptions>** - Configuration for the chosen session store.

## Advanced Route Configuration
Define routes with the following structure:

```
const routes = [
  {
    path: '/example',
    method: 'get',
    validator: yourYupValidator,
    handler: (req, res) => {
      // Route logic
    },
  },
  // ... more routes
];
```

The idea being that you can have one route per file, something like:
```
function route(request, response){
    response.status(200).send("Hello world!")
}

const schema = yup.object({}).shape({
  name: yup
    .string()
    .typeError("Name must be a string")
    .max(64, "Name is too long")
    .required(),
})

export default route = {
    path: "/example",
    method: "post",
    validator: schema,
    fn: route
}
```

So then you can barrel export them to cleanly validate and use your routes as:
```
import exampleRoute from './example'
export const routes = [
    exampleRoute,
]
```

## Defaults
- Comes with a /ping route automatically, that returns status 200 and the text "pong"
- Will auto implement express helmet, cookie parser, json body parsing, and rate limiting as middleware.
- So much easier to use a static "public" folder
- If an "index.html" file exists in the specified public folder, all 404 GET requests will serve the index.html file.
- Will trust proxy by default (allowing an API server to serve the "public folder" much smoother)
- All request types will automatically have the "request.session" type added onto it.
- You can use the types "Request" and "Response" exported from this package for an easier session-typed flow.

## License
This project is licensed under the MIT license.

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