npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

navarrotech-express

v1.0.29

Published

A standardized set of express utils wrapped into one

Downloads

14

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 - Customize Helmet configuration.
  • rateLimitOptions: Partial - Configure rate limiting.
  • sessionSecret: string - Secret for signing the session ID.
  • sessionSettings: Partial - Additional session configuration.
  • publicFolderPath: string - Path to the folder for serving static files.
  • storeSettings: Partial | Partial - 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.