Middleware for jb-router allowing transparent serving of SCSS as CSS


jb-router-scss is a plugin for jb-router, easily enabling on-the-fly compilation of SCSS to CSS. In this way, there is no need for a build step before deployment.

First, install with npm:

npm install jb-router
npm install jb-router-scss

and then

var Router = new (require("jb-router"))();
var SCSS = require("jb-router-scss");

Router.Get(/^\/js(\/.+)/, Router.StaticHandler("./static/js"));
Router.Get(/^\/css(\/.+)/, SCSS.CompileSCSS("./static/scss"));

Router.Listen({ "Port": 4000 });

jb-router-scss exposes one function:

  • LocalPath: a string with the path to the directory, on the server, of the SCSS files to be served by the route.
  • returns a Router::RequestHandler which expects one regular expression group, the file location relative to LocalPath.

Example: see above.


  • The request handler expects a request for a file with extension .css. It will then look in LocalPath for the same file but with an extension of .scss. For example, a request for /css/style.css will be answered with the compiled version of ./static/scss/style.scss.

  • The compiled CSS is served with content type text/css.