Whee is a very simple framework/router/thing for node that emphasizes magic. Things just work, even though they probably shouldn't. Some batteries included.
WARNING: This is more of a whimsical little experiment than a production-ready web framework. Seriously, I made most of this on a plane on very little sleep. If you want something more battle-tested and realistic (and you should), check out express, restify or hapi.
# npm i --save whee
First of all, require it:
var w =
And now, here's a Hello World:
Go ahead and try it! It's that simple! Whee!
You can also do all your other favorite HTTP verbs, like
w object is also your
this object, so you can call it that way, which is sometimes handy. Especially for CoffeeScript people.
//CoffeeScriptwget '/'-> @send 'Hello, World!'listen 3000
You have access to
sendError on the
w object, which are all pass-throughs to send-data.
You have access to
object, which are all pass-throughs to [body](https://www.npmjs.org/package/body). Instead of being passed in to the callback, the parsed body is then attached atw.body`.
Heresy? Yup, probably. Too bad.
There's also some basic redirect and static file stuff built in, but I'm a lazy README author so you can find those in the tests.
This magic comes from hiding the necessary bits (like your
res objects that you're used to) away in continuation local storage. Go read up on it. You'll love it! Also, it explains this stuff way better than I do.
Basically it lets you keep a context around for as long as your continuation chain lasts. For our purposes, that means the length of an HTTP request and response cycle. This is great news because we can hide stuff away in there!
res aren't gone forever. There's accessible at
w.res, so long as you're inside a handler.
If you want to hide your own stuff in there, you've got a few options:
whee namespace from
cls and interact with it directly:
var ns =;// then, somewhere in a request handler ...ns;// ....var session = ns;
You can also use your own namespace.
This sets up accessors on the
var w = ;w;// then, somewhere in a request handler ...w;// ....var session = wmysessionthing;
This is how the builtins are added!
context object is provided for you on
w so you can just put stuff there:
// somewhere in a request handler ...wcontextmysessionthing = some: 'thing';// ...var session = wcontextmysessionthing;
With each of these, remember that this stuff carries over to your next continuation, and so on, until you're done dealing with that request.
What about your connect/express middleware? Well we wouldn't want to leave that giant mountain of code behind. Luckily there's a pretty cool function called
wrap that we can use. It takes a function that would ordinarily take in a request and response object, and returns a function that has those arguments already prepended via whee's magic.
var w = ;var morgan = w;// morgan is a pretty good logging middleware;
Yes, for now, you'll have to call your middlewares directly. But being deliberate like this is half the fun right? Wheeeeeee!!!
See LICENSE file.