# create-router

> create a simple, fast, barebones, express-like router

Latest version **1.1.0** (published 2022-09-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install create-router
pnpm add create-router
yarn add create-router
bun add create-router
```

Provides the command `create-router`.

## 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.1.0 |
| Published | 2022-09-20 |
| First published | 2022-09-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ephf |
| Maintainers | ephf |
| Keywords | router, express, http, server, ws, websocket |

## Links

- npm: https://www.npmjs.com/package/create-router
- npm.io page: https://npm.io/package/create-router

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-09-20
- 1.0.2 — 2022-09-17
- 1.0.1 — 2022-09-17
- 1.0.0 — 2022-09-17

## README

# Create Router

🎉 Lightweight, easy to use alternative to express

## Usage

```bash
$ npx create-router [port]
```

Run the project any time from the `index.js` file. This file will run any files in your `routes/` directory.

create a route by creating a file in your routes directory like this

```js
// ping.js
const router = require("@router");

router.get("/ping", ({ res }) => {
  res.end("pong");
});
```

Additionally, you can add arguments and allow the requested path to extend infinitly far like this

```js
// /ping/<args[0]>
router.get("/ping/$", ({ args, res }) => {
  res.end(args[0]);
});

// /ping/...
router.get("/ping/*", ({ res }) => {
  res.write("pong");
});
```

Additionally, you can use a very bare-bones `WebSocket` route and middleware

```js
router.ws("/notify", (socket) => {
  socket.on("data", data => {
    const milliseconds = Number(data) * 1000;
    setInterval(() => {
      socket.write("ping!");
    }, milliseconds);
  });
});

router.use((req, res) => {
  res.setHeader("Content-Type", "text/plain");
});
```

There are also shorthand statements included for json reading and writing

```js
const messages = [];

router.post("/message", ({ req, res }) => {
  req.json().then(message => {
    messages.push(message);
    res.json({
      messageData: message,
      message: "Your message was successfully posted"
    });
  });
});
```

Any unused routes will be automatically directed to the `views/` folder.

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