Learn SAILS with Real Code Examples

Updated Nov 27, 2025

Explain

Sails.js follows the MVC pattern and provides auto-generated REST APIs for your models.

It is built on top of Express.js but adds conventions for scalability and maintainability.

Supports WebSockets for real-time communication with clients.

Integrates with various databases via Waterline ORM.

Highly modular with support for hooks, policies, and custom adapters.

Core Features

MVC architecture with controllers, models, and views

Waterline ORM for database abstraction

Blueprint APIs for automatic CRUD endpoints

Policy system for authentication and authorization

Socket.io integration for real-time features

Basic Concepts Overview

Model - defines database schema

Controller - handles HTTP requests

View - optional template rendering

Policy - request pre-processing for auth or validation

Hook - extend Sails.js functionality

Project Structure

api/models - database models

api/controllers - request handlers

api/services - reusable business logic

config/ - environment and database configs

views/ - optional templates

Building Workflow

Generate models and controllers via CLI

Define associations and schema in models

Use blueprint routes or create custom routes

Implement business logic in controllers/services

Test APIs and lift the server locally

Difficulty Use Cases

Beginner: simple CRUD API with blueprints

Intermediate: API with policies and custom routes

Advanced: real-time app using WebSockets

Expert: multi-database, complex associations

Enterprise: SaaS platform with scalable backend

Comparisons

Sails.js vs Express: Sails higher-level MVC, Express lightweight

Sails.js vs NestJS: Sails dynamic JS/Node, NestJS TypeScript/OOP

Sails.js vs LoopBack: both generate APIs; Sails more real-time focused

Sails.js vs Meteor: Sails for Node backends, Meteor full-stack JS

Sails.js vs Django: Node.js ecosystem vs Python ecosystem

Versioning Timeline

2012 - Initial release by Mike McNeil

2013 - Version 0.10 with core MVC features

2015 - Version 0.11 introducing hooks and policy system

2017 - Version 1.0 stable release

2025 - Latest version with modern Node.js support and WebSocket enhancements

Glossary

Model - defines schema and database interaction

Controller - handles requests and business logic

View - optional template for rendering

Policy - middleware for auth or validation

Hook - extend framework functionality