tiny-router
A simple routing library targeting embedded system where every byte counts. Right now there are few embedded systems running Javascript: Tessel, BeagleBone, RaspberryPi, and Espruino.
- Currently testing on Tessel, Espruino, BeagleBone, and Raspberry Pi
Installation
npm install tiny-router
Features
- Simple routing
- Supports GET, POST, PUT, DELETE. It can be extended by using the methodAdd fn
- Retrieving submitted data from the req.body object
- Light weight, only 160 lines of code to get an express like experience
Methods
-
use: Allow to overwrite default values configurations: ('static', 'defaultPage') and default methods: ('readFile', 'fileExist') this is useful when different embedded system read the file system differently. Also it gives access to the request and response object before the routing tables are created.
//Changing defaultPagerouter;//Setting a public folderrouter;//Creating a URL loggerrouter; -
Router: Return the routing table created from the get, post, put, etc.. methods
//Setting Routing tablehttp; -
listen(port): Return a instance of http.createServer(router.Router()).listen(port)
//A simple way to create serverrouter; -
addMethod(method): Allow the extension of supported method from the supported list: (GET, POST, PUT DELETE)
router;router; -
addMimeType(mimeObject): It extends the mime types supported by the server. It can use a third party mime type detector by overwriting the getMime method
router; -
getMime(file): Retrieves mime type
var type = router; -
send(msg): Sends data
var body = '<!DOCTYPE html>''<html ng-app="tessel">''<head>''</head>''<body style="background-color:#222;">''</body>''</html>';res; -
sendImage(img): Sends an image
res;
Examples:
Tessel lights
var router = tessel = ; var lights = green: tesselled0 blue: tesselled1 red: tesselled2 amber: tesselled3; router ; router;
Tessel Camera Module
var tessel = router = camera = ; router; router; camera; camera;
Raspberry Pi
var router = gpio = ; var { gpio; } { gpio; }; router; router; router; router; router;
Version
0.0.7: Added the sendImage method. Great for creating app to work with Tessel Camera module 0.0.8: Added the example folder 0.0.9: Minor changes to the gitignore file 0.1.0 Adding sample code for Raspberry Pi 0.1.2 Changing internal method to Async in order to interact with the filesystem. 0.1.6 Adding stream support and other engine templates
License
MIT
Free Software, Hell Yeah!