# way **Repository Path**: mirrors_scottcorgan/way ## Basic Information - **Project Name**: way - **Description**: Simple, Standalone/Connect/Express routes - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # way Simple, Standalone/Connect/Express routes ## install ``` npm install way --save ``` ## Usage ### Express/Connect ```js var http = require('http'); var connect = require('connect'); var route = require('way'); var app = connect(); app.use(route({ method: 'GET', path: '/my-path', before: function (req, res, next) { // Do something here next(); }, handler: function (req, res) { res.end('you got served!'); } })); http.createServer(app).listen(3000); ``` ### Standalone ```js var connect = require('connect'); var route = require('way'); var myRoute = route({ method: 'GET', path: '/my-path/:id', before: [ function (req, res, next) { // Do something here next(); }, function (req, res, next) { } ], handler: function (req, res) { console.log(req.params.id); res.end('you got served!'); } }); http.createServe(function (req, res) { myRoute(req, res); }).listen(3000); ``` ## Api ### route(options) #### Options * `path` - the route. This pathname works exactly like Express routes. (i.e. `/users/:id/friends/:friendId`, etc.) * `method` - http method type - `GET`, `POST`, etc. Defaults to `GET`. * `before ` - a single function or an array of functions to run before the handler. * they take the following method signature (similare to Connect/Express middleware): ```js route({ before: function (req, res, next) { next(); } }); ``` * `handler` - the final method called on the matching route. * this uses the following method signature: ```js route({ handler: function (req, res) { res.end(req.params); } }); ``` ## Run Tests ``` npm install npm test ```