New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

roosevelt

Package Overview
Dependencies
Maintainers
1
Versions
257
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roosevelt

Roosevelt MVC web framework

  • 0.4.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
297
increased by748.57%
Maintainers
1
Weekly downloads
 
Created
Source

roosevelt.js NPM version Dependency Status Gittip

Roosevelt is a new web framework for Node.js which uses Teddy for HTML templating and LESS for CSS preprocessing.

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.

Table of contents

Why use Roosevelt?

Roosevelt is easy to use and has a low learning curve, unlike many other popular Node.js-based web frameworks.

Reasons for this include:

  • Minimal boilerplate to get started. All the magic of Express is preconfigured for you.
  • Default directory structure is simple, but easily configured.
  • Concise MVC architecture.
  • Teddy HTML templates are much easier to read and maintain than popular alternatives.

Create and run a Roosevelt app

Install the command line tool globally (may require admin or root privileges):

npm install -g roosevelt

Use the command line tool to create a sample app:

roosevelt create myapp

Change into your new app's directory and then install dependencies:

cd myapp
npm install

Run your app:

node app.js

Other ways to run Roosevelt apps

Run your app in production mode:

export NODE_ENV=production && node app.js

Run your app on two CPUs:

node app.js -cores 2

Run your app on all your CPUs:

node app.js -cores max

While developing your app, a more convenient way to run the app is to use the npm start script.

The npm start script will run your app through nodemon and will automatically restart whenever you modify any JS, JSON, LESS, or HTML files.

Make sure you install nodemon first via npm install -g nodemon (may require admin or root privileges) and then simply execute this command:

npm start

Default directory structure

  • app.js: main app file.
  • mvc: folder for models, views, and controllers.
    • controllers: folder for controller files.
    • models: folder for model files.
    • views: folder for view files.
  • node_modules: a standard Node.js folder where all modules your app depends on (such as Roosevelt) are installed to.
  • package.json: a standard Node.js file for configuring your app.
  • public: all contents within this folder will be exposed as statics.
  • statics: folder for CSS, images, JS files, LESS files, and other statics. Some of the contents of this folder are symlinked to from public, which you can configure (see below).
    • css: folder for CSS files.
    • images: folder for image files.
    • js: folder for JS files.
    • less: folder for LESS files.

Configure your app

Roosevelt is designed to have a minimal amount of boilerplate so you can focus on just writing your app. All parameters are optional. As such, by default, all that's in app.js is this:

require('roosevelt')();

Roosevelt will determine your app's name by examining "name" in package.json. If none is provided, it will use Roosevelt Express instead.

Inside app.js, you can pass any of the below optional parameters to Roosevelt via its constructor like so:

require('roosevelt')({
  paramName: 'paramValue',
  param2:    'value2',
  etc:       'etc'
});

Each param can also be defined in package.json under "rooseveltConfig".

Parameter list

ParamDescriptionDefault
portThe port your app will run on.Either process.env.NODE_PORT or if that's undefined, then 43711
modelsPathRelative path on filesystem to where your model files are located.mvc/models
viewsPathRelative path on filesystem to where your view files are located.mvc/views
controllersPathRelative path on filesystem to where your controller files are located.mvc/controllers
notFoundPageRelative path on filesystem to where your "404 Not Found" controller is located. If you do not supply one, Roosevelt will use its default 404 controller instead.404.js
internalServerErrorPageRelative path on filesystem to where your "500 Internal Server Error" controller is located. If you do not supply one, Roosevelt will use its default 500 controller instead.500.js
serviceUnavailablePageRelative path on filesystem to where your "503 Service Unavailable" controller is located. If you do not supply one, Roosevelt will use its default 503 controller instead.503.js
staticsRootRelative path on filesystem to where your static assets are located.statics
cssPathRelative path on filesystem to where your CSS files are located.statics/css
lessPathRelative path on filesystem to where your LESS files are located.statics/less
publicFolderAll files and folders specified in this path will be exposed as statics.public
publicStaticsStatic folders to make public. Only these subfolders of your staticsRoot will be accessible to end users.['css',
'images',
'js']
prefixStaticsWithVersionIf set to true, Roosevelt will prepend your app's version number from package.json to your statics URLs. Versioning your statics is useful for resetting your users' browser cache when you release a new version.false
versionNumberLessVarWhen this option is activated, Roosevelt will write a file named version.less to your less directory containing a variable with your desired name populated with your app's version number derived from package.json.

This option is disabled by default. Activate it by supplying a desired variable name to the parameter.

This feature is useful in conjunction with prefixStaticsWithVersion, as it allows you to construct URLs in your LESS files such as url('/@{staticsVersion}/images/i.png'), allowing you to version all of your statics at once simply by changing your app's version number in package.json.
undefined
alwaysHostStaticsBy default in production mode Roosevelt will not expose the statics folder. It's recommended instead that you host the statics yourself directly through another web server, such as Apache or nginx. However, if you wish to override this behavior and have Roosevelt expose your statics even in production mode, then set this setting to true.false
disableLoggerWhen this option is set to true, Roosevelt will not log HTTP requests to the console.false
localhostOnlyListen only to requests coming from localhost.true
disableMultipartWhen this option is set to true, Roosevelt will not parse enctype['multipart/form-data'] forms.false
formidableSettingsSettings to pass along to formidable using formidable's API.undefined
maxLagPerRequestMaximum amount of time in miliseconds a given request is allowed to take before being interrupted with a 503 error. (See node-toobusy)70
shutdownTimeoutMaximum amount of time in miliseconds given to Roosevelt to gracefully shut itself down when sent the kill signal.30000 (30 seconds)

Events

Roosevelt also provides a series of events you can attach code to by passing a function to the desired event as a parameter to Roosevelt's constructor like so:

require('roosevelt')({
  onServerStart: functiom(app) { /* do something */ }
});

Event list

EventDescriptionArguments passed
onServerStartFired when the server starts.
onReqStartFired at the beginning of each new request.
  • req: the request object created by Express.
  • res: the response object created by Express.
  • next: callback to continue with the request. Must be called to continue the request.
onReqBeforeRouteFired just before executing the controller.
  • req: the request object created by Express.
  • res: the response object created by Express.
  • next: callback to continue with the request. Must be called to continue the request.
onReqAfterRouteFired after the request ends.

Making controller files

Controller files are just standard Express routes. A route is the term Express uses for URL endpoints, such as http://yoursite/blog or http://yoursite/about.

To make a new controller, just make a new file in the controllers directory. For example:

module.exports = function(app) { // app is the Express app created by Roosevelt

  // standard Express route
  app.get('/about', function(req, res) {
  
    // use Roosevelt to load a data model
    var model = app.get('model')('about');
    
    // render a Teddy template and pass it the model
    res.render('about', model);
  });
};

Making model files

Since the above example requires a model file named about, you will need to make that too. To do that, place a file named about.js in mvc/models.

Here's a simple example about.js data model:

module.exports = {some: 'data'};

Making view files

Views are Teddy templates. See the Teddy documentation for information about how to author Teddy templates.

Using LESS with Roosevelt

Using LESS with Roosevelt is optional.

Roosevelt will automatically compile any (.less) files in your LESS folder down to minified CSS (.css) files of the same name in your CSS folder. Note: This will overwrite any preexisting CSS files of the same name, so be careful.

The CSS minifier used by LESS is YUI Compressor.

Express variables exposed by Roosevelt

Roosevelt supplies several variables to Express that you may find handy. Access them using app.get('variableName').

Express variableDescription
expressThe express Node.js module.
teddyThe teddy Node.js module. Used for templating.
formidableThe formidable Node.js module. Used for handling multipart forms.
appNameThe name of your app derived from package.json. Uses "Roosevelt Express" if no name is supplied.
appDirThe directory the main module is in.
packageThe contents of package.json
staticsRootFull path on the file system to where your app's statics folder is located.
publicFolderFull path on the file system to where your app's public folder is located.
modelsPathFull path on the file system to where your app's models folder is located.
viewsPathFull path on the file system to where your app's views folder is located.
controllersPathFull path on the file system to where your app's controllers folder is located.
paramsThe params you sent to Roosevelt.
portPort Roosevelt is running on.
modelMethod to return a model. Calling app.get('model')('modelName') will return a specified model from your models folder.

Warning: Roosevelt is beta software!

Not many apps have been written using Roosevelt yet, so it's entirely possible that there will be some significant bugs.

You should not use Roosevelt in production yet unless you're willing to devote some time to fixing any bugs you might find.

Dependencies

  • express - a minimal and flexible Node.js web application framework
  • teddy - an easy-to-read, HTML-based, mostly logic-less DOM templating engine
  • less-middleware - Connect middleware for LESS compiling
  • formidable - a Node.js module for parsing form data, especially file uploads
  • wrench - used for recursive file operations and used by the CLI tool to help you create your sample app
  • toobusy - monitors the process and serves 503 responses when it's too busy
  • update-notifier - used to tell you when there's a new version of Roosevelt

License

All original code in Roosevelt is licensed under the Creative Commons Attribution 4.0 International License. Commercial and noncommercial use is permitted with attribution.

Keywords

FAQs

Package last updated on 26 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc