fogo 🔥
Yet another node.js framework, but simpler.
Install
npm install fogo --save
fogo
supports only node 8+ because of async
/await
.
Why? Why? Why?
fogo
, means fire
in Portuguese 🤷♀️. It is basically a wrapper for the node.js http module.
Sometimes Express
, which is a good framework, is too much for your needs or too heavy because of its tons of dependencies, especially if you do microservices or have a lot of CI/CD going on.
Only use fogo
if you want to use the http
module provided by node.js but without dealing with routes.
fogo
does not support middlewares. You really don't need it.
What fogo
is good for:
- microservices
- restful/json apis
What fogo
is not good for:
- applications using template engines
- monolithic applications
An alternative to fogo
is micro
.
Usage
const fogo = ; const handlers = { res; // Pure node.js! res; // you see?!? } '/products/:id': get: async { try await ; // Why middlewares? :) const product = await ; res; res; catch err res; res; } '/customers': post: async { try await ; // Why middlewares? :) const body = await ; const customer = await ; res; res; res; catch err res; res; } ; const notFoundHandler = { res; res;}; const server = fogo; // server is just a wrapper for the http.Server classserver; server;
API
createServer
const server = fogo;
Since fogo.createServer
returns a http.Server
class, you should be able to use all its methods. Please, check out the documentation for more information.
It creates a server that you can listen to. It accepts two arguments:
handlers
: object - required
An object containing your handlers for each route with/without specifying the http method. Specify a function if you want that route to listen to all http methods.
const handlers = { res; } '/welcome': { res; } { res; } ;
Arguments received:
req
: http.IncomingMessageres
: http.ServerResponseurl?
: url.UrlWithParsedQueryparams?
: object
notFoundListener
: function
If none of you handle has the requested route, this callback is called.
fogo
provides a default one.
{ res; res;}
The response will look like:
Not Found
Arguments received:
req
: http.IncomingMessageres
: http.ServerResponseurl?
: url.UrlWithParsedQueryerror?
: Error
errorHandler
: function
It's called when an exception is thrown on the request.
fogo
provides a default one.
{ console; res; res;}
The response will look like:
Internal Server Error
Arguments received:
req
: http.IncomingMessageres
: http.ServerResponseurl?
: url.UrlWithParsedQueryerror?
: Error
Made with ❤️ enjoy it!