Fatless is a small Framework aimed at being modular. It exposes a small API but a lot of utilities, and some modules are already included so you don't need to install them. Fatless is promise-based, using q.
npm install fatless --save
Here's an example, very simple "Hello, World" app:
Let's go over it line by line:
The Fatless module exposes a function that creates all the global variables. These are
Q (the q lib). The function requires a parameter, the root directory of the application.
route is a method from the
Router. It allows to create a route with any path/method. The first parameter is the path, the second is the middleware and the third a callback. Fatless uses path-to-regexp to match parameters, which you can find in
req.params. If you want to change the HTTP Method, prepend it to the path (ex:
resbody = "Hello, World!";
res, an instance of
Response, exposes a
body variable. The data will only be sent when the request completely ends. Should you do asynchronous stuff, make sure to return a promise that resolves when
body is set, or the response would already be sent.
Ok, so we'll split this. First of, we call
.start, which takes an argument: the application configuration. One thing you need to supply is a
start returns a promise which will resolve when all modules are loaded and the web server listening. It will reject on any error during initialisation.
That should get you started on the most basic applications. If you need more, read the API !
This is still incomplete, and the API is pre-alpha.
F(atless) is the global framework variable. It doesn't contain much.
config: Configuration you passed to
F.start(), merged with the default configuration (
F._defaultConfig, don't touch that).
start(config): Starts the app
R(outer) is the application router. It can define classic routes, middleware and error handlers.
route(path [, name], middleware, handler): Adds a route. All middleware will be called in that order.
middleware(name, handler): Adds a middleware.
handlermay return a promise.
error(code, handler): Adds an error handler.
test(path, req): Makes an internal request to path, using the provided request.
All handlers (route, middleware, error) are called like this:
handler(request, response). Error handlers also have
req.code, the error code.
When creating routes (
R.route), the format of
path can be:
[PATH](the method will be
/blog(Same all the one up)
U(tils) contient des fonctions utilitaires ainsi que des librairies comme
merge: deep-merges the arguments. Uses deepmerge.
list(dir): List files & directories in a directory. Returns a promise.
listSync(dir): Synchronous version of
listFiles(dir): List files in a directory. Returns a promise.
listFilesSync(dir): Synchronous version of
listDirs(dir): List directories in a directory. Returns a promise.
listDirsSync(dir): Synchronous version of
Fatless is MIT-licensed. More information in