non-fancy-router
v1.0.2
Published
a non-fancy, minimalistic node.js server router
Downloads
5
Maintainers
Readme
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 you want to send from your server, or a function.
Install
With npm installed, run
$ npm install non-fancy-router
License
MIT