# hyper-express-route-path

> A small module that helps extract the path of a certain route in hyper-express.

Latest version **1.0.1** (published 2022-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install hyper-express-route-path
pnpm add hyper-express-route-path
yarn add hyper-express-route-path
bun add hyper-express-route-path
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-10-30 |
| First published | 2022-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anthony Mugendi |
| Maintainers | nguru |
| Keywords | hyper-express, route, path, extract, file-path |

## Links

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

## Dependencies (1)

- [path-match](https://npm.io/package/path-match.md) ^1.2.4

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-10-30
- 1.0.0 — 2022-10-28

## README

<!--
 Copyright (c) 2022 Anthony Mugendi

 This software is released under the MIT License.
 https://opensource.org/licenses/MIT
-->

# hyper-express-route-path

This is a tiny module that uses [path-match](https://www.npmjs.com/package/path-match) to determine the exact path extracted from a route.

This was built to work with [hyper-express](https://www.npmjs.com/package/hyper-express) and I use it to help manage static file serving.

## Ah! Oh! What does it do?

Say you have the route `/assets/*` to server your assets, and you try to access the file `/assets/vids/1.mp4`, it calculates the route path to be `/vids/1.mp4` so you can look for that file in your static directory.

Why this is important is because static files will effectively be served off many routes and you will need a way to map to them.

## Usage

You can use this as a middleware or within the route.

```javascript
const HyperExpress = require('hyper-express');
const webserver = new HyperExpress.Server();

// require module
const heRoutePath = require('hyper-express-route-path');

// to use it as a middleware
webserver.use(heRoutePath.middleWare);

// Create GET route to serve 'Hello World'
webserver.get('/*', async (request, response) => {

	// Now every request object will have a new property; routePath
	response.send(request.routePath);
	// => '/vids/1.mp4' when accessing /vids/1.mp4

	//You can also use it within a route as follows
	let filePath = heRoutePath.routePath(request);
	// Of course we probably don't need this as we have already used it as a middleware ;)
	response.send(filePath);
	// => '/vids/1.mp4' when accessing /vids/1.mp4

});

// Activate webserver by calling .listen(port, callback);
webserver
	.listen(80)
	.then((socket) => console.log('Webserver started on port 80'))
	.catch((error) => console.log('Failed to start webserver on port 80'));
```

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