Sails.js

Realtime MVC Framework for Node.js

Install Documentation Changelog

image_devInTub@2x.png

Sails.js

Sails.js makes it easy to build custom, enterprise-grade Node.js apps. It is designed to resemble the MVC architecture from frameworks like Ruby on Rails, but with support for the more modern, data-oriented style of web app development. It's especially good for building realtime features like chat.

Intro to Sails.js

Installation

To install the latest stable release with the command-line tool:

sudo npm -g install sails

Creating a New Sails.js Project

Create a new app

# Create the app
sails new testProject

Lift Sails

# cd into the new folder
cd testProject

# Fire up the server  
sails lift

The default port for Sails is 1337. At this point if you visit http://localhost:1337/ You will see the default index.html page.

Creating a Model

Creating a model is very easy with the command line tool. You can even define attributes and their type by adding arguments at the end of the command. To generate a User model, enter the following:

sails generate user

If you check out your app, you'll notice that this created a file at /api/model/User.js.

What's Better Than Scaffolding? How About a free JSON API?

Sails.js API scaffolding is nothing like Rails scaffolding. HTML scaffolds just don't make sense for modern web apps (no one uses them.) Instead, Sails automatically builds a RESTful JSON API for your models. And here's the thing, it supports HTTP and WebSockets. By default, for every controller you create, you get the basic CRUD operations created automatically.

For instance, after generating the User model above, if you visit http://localhost:1337/user/create, you'll see:

{
  "createdAt": "2013-01-10T01:33:19.105Z",
  "updatedAt": "2013-01-10T01:33:19.105Z",
  "id": 1
}

That's it! You just created a model in the database! You can also find, update, and destroy users:

# List of all users
http://localhost:1337/user

# Find the user with id 1
http://localhost:1337/user/1

# Create a new user
http://localhost:1337/user/create?name=Fisslewick
(or send an HTTP POST to http://localhost:1337/user)

# Update the name of the user with id 1
http://localhost:1337/user/update/1?name=Gordo
(or send an HTTP PUT to http://localhost:1337/user/1)

# Destroy the user with id 1
http://localhost:1337/user/destroy/1
(or send an HTTP DELETE to http://localhost:1337/user/1)

Additional Features

Sails.js does a few things other Node.js MVC frameworks can't do:

  • Automatically generated JSON API for manipulating models means you don't have to write any backend code to build simple database apps
  • Built-in authentication, role-based access control, and customizable policies assignable at the controller/action level
  • Transport agnostic routing: Sails controllers also handle Socket.io / WebSocket messages. This makes it much easier to send the server-originated or 'comet' notifications you need for features like chat, realtime analytics, and multiplayer games.
  • Automatic asset minification with Rigging: Your UI code is automatically included in development mode, and minified into a simple, gzipped file in production.
    • Support for:
    • CoffeeScript
    • LESS

To learn more, check out the documentation here: https://github.com/balderdashy/sails/wiki/_pages

Contribute

We're making the best free, open-source Node.js framework in the world, but we can't do it alone. Contributors are absolutely essential to the robustness and continued lifecycle of Sails.

You can learn more about contributing to Sails here, including my best pass at some step by step instructions for you to get up and running.


Changelog

See what's new in the latest version

Google Group

If you have questions, ideas, or run into a problem, post it to our google group and either I or someone else will be able to help you.

Sails.js Google Group




IRC

We're #sailsjs on freenode.

#sailsjs IRC on freenode

Dependencies and Compatibility

Tested with node 0.8.1 Sails is built on the rock-solid foundations of ExpressJS and Socket.io.

icon_circleheart@2x.png

Who Built This?

The Sails framework was developed by Mike McNeil (@mikermcneil) and is supported by Balderdash (@balderdashy), a realtime web & mobile studio I started with Heather White (@hdesignsit) in Austin, TX.

After building a few realtime javascript apps and taking them into production, we realized that the JavaScript development landscape is very much still the Wild West. Over time, after trying lots of different methodologies (on the front end and the back), we decided to crystallize all of our best practices into this framework. I hope it saves you some time :)

icon_circlelightbulb@2x.png

License

Sails is built around so many great open-source technologies that it would never have crossed our minds to keep it proprietary. We owe huge gratitude and props to TJ Holowaychuk (@visionmedia) and Guillermo Rauch (@guille) for the work they did, as well as the stewards of all the other open-source modules we use. Sails could never have been developed without your tremendous contributions to the node community.

The MIT License (MIT)

Copyright © 2012-2013 Mike McNeil

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.