roosevelt.js
Roosevelt is a web framework for Node.js which uses teddy.js for HTML templating.
Built on Express, Roosevelt is designed to abstract all the crusty boilerplate necessary to build a typical Express app, sets sane defaults with mechanisms for override, and provides a uniform MVC structure for your app based on the Node.js EventEmitter.
Installation
Install command line tool globally (may require sudo):
npm install -g roosevelt
Make an app
Use the command line tool to create a sample app:
roosevelt create myapp
Change into your new app's directory and then install dependencies (may require sudo):
cd myapp
npm install .
Run the app:
node app.js
That's pretty much it.
What's in app.js?
Just this:
GLOBAL.app = require('roosevelt');
app({
});
Roosevelt is designed to have a minimal amount of boilerplate so you can focus on just writing your app. All parameters are optional.
Note: app must be defined as a global variable so that your models and controllers can access its utility methods later.
Parameters
Here's what the parameters mean:
name
: the name of your appport
: the port your app will run on (default is 43711)modelsPath
: path on filesystem to where your model files are located (default is "mvc/models")viewsPath
: path on filesystem to where your view files are located (default is "mvc/views")controllersPath
: path on filesystem to where your controller files are located (default is "mvc/controllers")imagesPath
: path on filesystem to where your image files are located (default is "statics/i")cssPath
: path on filesystem to where your CSS files are located (default is "statics/css")lessPath
: path on filesystem to where your LESS files are located (default is "statics/less")jsPath
: path on filesystem to where your JS files are located (default is "statics/js")statics
: list of paths on filesystem to where your statics are located (setting this param overrides and supersedes imagesPath, cssPath, lessPath, and jsPath)customConfigs
: use this to define a custom function to be executed during the Express config stage if you need one
Making controllers and models
URL endpoints (also called routes) are defined by controller files.
The Roosevelt framework will automatically assign a route matching each controller's filename.
As such, to make a new route, just make a new file in the controllers directory.
For example, suppose we make a new file in mvc/controllers
called hello.js
.
That will make a new URL endpoint /hello
on your app.
Here's a sample hello.js
controller:
module.exports = app.loadModel('helloModel');
app.on('helloReady', function(res, model) {
res.render('hello.html', model);
});
The above controller file will make a new URL endpoint /hello
on your app and load a model from the mvc/models
directory called helloModel.js
.
When the helloModel.js
is done gathering the data the view will need, it is expected that it will emit an event called helloReady
which will be caught by your hello.js
controller so that the hello.html
view can be rendered with the fully composed model.
As such, your helloModel.js
file should look something like this:
var model = function(req, res) {
model.data = {some: 'data'};
app.emit('helloReady', res, model.data);
};
module.exports = model;
That's it. Just follow that pattern to do MVC in your app.
LESS CSS support
When a Roosevelt server is started, it will automatically compile any LESS (.less
) files in your LESS folder down to minified CSS (.css
) files of the same name in your CSS folder.
In the process it will overwrite any preexisting CSS files of the same name, so be careful.
Missing features
Here are some things still left to be implemented:
- Support for templating engines other than teddy
- HTTPS support
- Support for more custom HTTP status code error pages
- Probably many other things
Dependencies
- events (bundled with Node.js) - a default Node.js module which provides an event emitter
- fs (bundled with Node.js) - a default Node.js module which provides filesystem access
- http (bundled with Node.js) - a default Node.js module which provides HTTP web server support
- express - a minimal and flexible node.js web application framework
- teddy - an easy-to-read, HTML-based, mostly logic-less DOM templating engine
- LESS - dynamic CSS language extensions
- wrench - used by the CLI tool to help you create your sample app
License
All original code in Roosevelt is licensed under the Creative Commons Attribution 3.0 Unported License. Commercial and noncommercial use is permitted with attribution.