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

@kyri123/express-app-router

v1.1.0

Published

[![Version package](https://badgen.net/npm/v/@kyri123/express-app-router)](https://npmjs.com/@kyri123/express-app-router) [![DL TOTAL](https://badgen.net/npm/dt/@kyri123/express-app-router)](https://npmjs.com/package/@kyri123/express-app-router) [![LATEST

Downloads

4

Readme

ExpressDirectoryRouter

Version package DL TOTAL LATEST RELEASE ALL CONTRIBUTOR

ExpressDirectoryRouter is a lightweight and flexible middleware for Express.js that simplifies routing by automatically handling routes based on the structure of your project directories.

Table of Contents

Installation

You can install ExpressDirectoryRouter using npm, yarn, or pnpm for example:

npm install @kyri123/express-directory-router

yarn add @kyri123/express-directory-router

pnpm add @kyri123/express-directory-router

Usage

To use ExpressDirectoryRouter, simply require it and use it as middleware in your Express application:

Javascript

const express = require('express');
const { installAppExpress } = require('express-directory-router');

const app = express();

// install routings with default settings
installAppExpress(app).then(() => {
	app.listen(3000, () => {
		console.log('Server is running on http://localhost:3000');
	});
});

Typescript

import express from 'express';
import { installAppExpress } from 'express-directory-router';

const app = express();

// install routings with default settings
installAppExpress(app).then(() => {
	app.listen(3000, () => {
		console.log('Server is running on http://localhost:3000');
	});
});

Middleware

Middleware can be used in the following formats the name of the file must ne middleware.(js|ts) Following named exports are supported:

  • GET
  • POST
  • PUT
  • DELETE
  • PATCH
  • GLOBAL -> GLOBAL is a special middleware that is executed for all routes and methods (also in subdirectories)
  • WILDCARD -> WILDCARD is a special middleware that is executed for all routes and methods (BUT NOT in subdirectories)
  • HEAD
  • OPTIONS
  • ALL
  • TRACE
import { type MiddleWareInit } from '@kyri123/express-directory-router';

export const GET: MiddleWareInit = async (payload) => {
	return [
		(req, res, next) => {
			return next();
		}
	];
};

export const GLOBAL: MiddleWareInit = async (payload) => {
	return [
		(req, res, next) => {
			return next();
		}
	];
};

Directory-Routes

Route the directory structure is as follows:

| Directory | Description | Directory | Express Route | | ---------------- | ----------------------------------------------------- | -------------------- | ------------------ | | XYZ | name of the Route for exmaple | xyz/123 | /xyz/123 | | [paramname] | will used for params | xyz/[paramname] | /xyz/:paramname | | [paramname...] | will used for params and route all subdirectorys here | xyz/[paramname...] | /xyz/:paramname* | | (xyz) | will ignored for routing so used for organisation | xyz/(group)/123 | /xyz/123 | | [...] | Will route all subdirectory here | xyz/[...] | /xyz/* | | XYZ | name of the Route for exmaple | xyz/123 | /xyz/123 |

Route-Functions

Routes can be used in the following formats the name of the file must ne ('get'|'post'|'put'|'delete'|'all'|'head'|'connect'|'options'|'trace').(js|ts): named exports:

  • middleware -> (optional) - Middleware for the route (see Middleware)
  • default -> (required) - The route handler must be a RoutingFunction


```ts
import { ResponseStatus, jsend, type MiddleWareInit, type RoutingFunction } from '@kyri123/express-directory-router';

export const middleware: MiddleWareInit = async (payload) => {
	return [
		(req, res, next) => {
			return next();
		}
	];
};

const handler: RoutingFunction = async ({ response, request, next, payload }) => {
	response.status(200).json(
		jsend(ResponseStatus.Success, {
			data: { message: 'Hello World' }
		})
	);
};

export default handler;

Documentation

You can find the detailed documentation for ExpressDirectoryRouter in the docs directory.

Contributing

We welcome contributions! If you find a bug or have an idea for a new feature, please open an issue or submit a pull request.

Please make sure to follow our code of conduct.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Thanks to the contributors of Express.js for providing a powerful web application framework.