trench

Simplistic, promise-based web framework for node.

Usage no npm install needed!

<script type="module">
  import trench from 'https://cdn.skypack.dev/trench';
</script>

README

trench

Build Status

:large_orange_diamond: Simplistic, promise-based web framework for node.

Features

  • Supports new ES6 features such as Promises and Sets.
  • Supports all HTTP methods listed in http.METHODS.
  • Prioritises speed and simplicity over a large feature-set or extensive options.
  • API modeled on the ever-popular Express.
  • In equivalent "Hello, World!" examples, it's faster than both hapi and Express.

Usage

  • Requires Node 6.0+
const Trench = require("trench");

const app = new Trench();

app.get("/", (req, res) => {
    res.end("<h1>Hello, World!</h1>");
});

app.listen(8080);

Recommended Modules

API

new Trench()

Returns a new app instance.

const app = new Trench();

Trench#use(function)

Specifices a middleware function to be used.

app.use((req, res) => {
    res.locals.startTime = Date.now();
});

Trench.static(root)

Returns a middleware function for serving static files.

app.use(Trench.static(__dirname + "/static"));

Trench#get(path, [ function, [ function, [ function ]]])

Specifices a GET route for the given path.

app.get("/", (req, res) => {
    res.locals.name = "Monty";
}, (req, res) => {
    res.end(`Hi, ${res.locals.name}!`);
});