A node.js webserver scaffold

Nails-Boilerplate: A Node Webserver Framework

This framework is designed to provide a lightweight, configurable MVC backend for node developers. With minimal dependencies, Nails offers a greater syntactical familiarity than php alongside the creative freedom of bleeding edge solutions like Rails and Django.

This boilerplate offers the basic necessities to get your MVC site off the ground. The modules used in Nails Boilerplate can be easily extended to produce the custom functionality to fit your needs, and you are encouraged to do so.

sudo npm install -g nails-boilerplate
nails init <app_name>

This will initialize a barebones app in the directory of the same name. Take a look at the self-documented config files and example controller and view before getting started. Additional controllers and views will automatically be imported into nails. Now just hook the new controllers in with some new routes and you're off to a good start.

cd app_name
npm install
node server

For your convenience, here is a quick outline of the main components of a nails application. Remember: each object comes with an example file to use for reference when building your application.

-- Coming soon... For now, take a look at the files in the example config directory --

Controllers are defined in app/controllers/. Each controller module should define a constructor (named function) to be used when initializing the controller. The name of the controller will be used to match routes defined in config/routes.js for incoming requests. Methods on the controller can be used to match actions, receiving , , as arguments. For Example:

module.exports = function HomeController() {
    this.index = function(paramsrequestresponse) {
        // default action 
    this.signin = function(paramsrequestresponse) {
        // does something then renders a view 
    this.helper_method = function() {
        // does something but does not have access to response 

defines a controller which will match any route to 'home#'. "index" and "signin" are actions which can be used to render a response to the client.

Docs coming soon...

Docs coming soon...

Docs coming soon...

Models are programmatic representations of data you wish to persist in a database. They are a special kind of object which come with 'save()' and 'fetch()' methods to (respectively) persist the model to the database or retrieve the model from the database and update its attributes. Consider app/models/user.js:

module.exports = function User(attr) {

When we execute the following code in the nails application, we create a user with the specified name and age, and save it to the database:

    // require user constructor 
    var User = require('<application root>/app/models/user.js');
    // create a user instance 
    var u = new User({name: 'foobar', age: 25});
    // save the user to the database;

And voila! The user is now available for future requests:

    var u2 = new User(); = <id of a persisted user>;
    // now update u2 with the data from the databse 

Note that Nails extends your model objects with the methods needed for interacting with a database, so you can focus on business logic.

Docs coming soon...

Stay tuned as nails evolves:

  • Intuitive support for template engines
  • Server/client redirects
  • Custom Request middleware
  • Fancy Logging
  • Sessions
  • Custom ORM/ODM support
  • Server security

Enjoy! Feature requests, bug reports, and comments are welcome on github.