Skip to content

jakeburden/non-fancy-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

non-fancy-router

a non-fancy, minimalistic node.js server router

The JavaScript here is very ✨ fancy ✨, but the router itself is not. Just pass it [a route, then a filename 📂 or function λ], and if the user goes to that route, the server will send that file or run that function.

Usage

const { createServer } = require('http')
const nonfancy = require('non-fancy-router')

const router = nonfancy([
  ['/', 'index.html'],
  ['/about', 'about.html'],
  ['/styles.css', 'styles.css'],
  ['/*', function (req, res) {
    // otherwise 404
    res.statusCode = 404
    res.end('404')
  }]
])

createServer(router).listen(9090, () => {
  console.log('The server is running on http://localhost:9090')
})

API

nonfancy([
  [UrlPattern, FileName || Function]
])

Pass non-fancy-router an array of routing arrays. The first routing array argument is a murl pattern, the second routing array argument is either the name of the file you want to send from your server, or a function.

Install

With npm installed, run

$ npm install non-fancy-router

License

MIT

About

a non-fancy, minimalistic node.js server router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published