Router Module

Build Status

The Nxus router is an Express compatible web server and router for Nxus applications.

Installation

In your Nxus application:

> npm install nxus-router --save

Usage

Defining a route

import {router} from 'nxus-router'

router.route('/', (req, res) => {
  res.send('Hello World')
})

Alternatively, you can specify a HTTP method:

router.route('GET', '/', (req, res) => {
  res.send('Hello World')
})

Adding Express/connect middleware

router.middleware((req, res) => {
  res.status(404).send('Nothing to see here')
})

Adding static files/directories

router.staticRoute("/my-prefix", myPath)

For example, myFile.txt in myPath is then available at the url /my-prefix/myFile.txt

Router provides Express based HTTP routing

new Router()

Extends NxusModule

Example
import {router} from 'nxus-router'
Instance Members
getRoutes()
getExpressApp()
middleware(route, handler, [method])
route([method], route, handler)
staticRoute(prefix, path)