Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A node webserver boilerplate mimicking Rails structure
JavaScript C HTML
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin/lib
example
lib
scripts
spec add spec for bin scripts. update app template
templates
.gitignore
README.md
index.js
package.json

README.md

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.

Install

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

API

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.

Config

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

Controller

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(params, request, response) {
        // default action
    };
    this.signin = function(params, request, response) {
        // 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.

Params

Docs coming soon...

Request

Docs coming soon...

Response

Docs coming soon...

Model

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) {
    this.set('name', attr.name);
    this.set('age', attr.name);
}

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
    u.save();

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

    var u2 = new User();
    u2.id = <id of a persisted user>;

    // now update u2 with the data from the databse
    u2.fetch();

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

View

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.

Something went wrong with that request. Please try again.