SlideShare a Scribd company logo
http://www.meetup.com/Pittsburgh-Node-js/
NICHOLAS MCCLAY
UX Developer

@nickmcclay
MEET YOUR NEIGHBOR
Framework Overview
SAILS HIGHLIGHTS
• Robust Node.js MVC web server framework
!

• Railsy features - scaffolding, DB agnostic ORM
!

• Automatically generated RESTful JSON API
!

• Out-of-the-box real-time socket.io integration
!

• Role based access policies and ACL
!

• JS/CSS asset bundling and minification (Grunt)
QUICK NOTE:
Convention > Configuration = Magic
WHAT IS A
SINGLE PAGE APPLICATION?
TRADITIONAL WEB APPLICATION
http://www.cutekitties.com/kitten/1

One Kitten Please!

HTTP Request
Response
HTML
JavaScript
CSS
TADA! WEB PAGE!
SINGLE PAGE APPLICATION
http://www.cutekitties.com#/kitten/1

One Kitten Please!

HTTP Request
Application

Response
HTML
JavaScript
CSS
/kitten/1?format=json

GET /kitten/1

A JAX Request
[{

"_id" : "abc124efg345",

"lives" : 9,

"curiousity" : "massive",

"cuteness" : 9999,

"eyes" : "blue",

"fur" : "yellow"

}]

Response
JSON
TADA! WEB APP!
Heading out to sea
SAILS VERSIONS
V0.9

Coming

V0.10
V0.10

Soon

• Current NPM default

• beta version (RC3)

• Reliable starting place

• Significant Refactors

• What I’ll be demoing

• API changes

in this presentation

• Associations
• Here be dragons…

https://github.com/balderdashy/sails-docs/blob/master/Migration-Guide.md
DOCUMENTATION SOURCES
Official Website Documentation

http://sailsjs.org/#!documentation

GitHub Documentation Repo
Coming

V0.10
Soon

https://github.com/balderdashy/sails-docs/tree/0.10
CREATE A NEW SAILS PROJECT
http://sailsjs.org/#!getStarted
0.10.0 NPM INSTALL WEIRDNESS

If you encounter this, try:
npm install -g
SAILS CLI BASICS
Turn on asset linking

Make a new app

sails new <appName>
Run App

sails lift

--linker

Set Env Config

Display all logs

--dev --prod --verbose

Display Sails.js Version

sails version
SAILS SCAFFOLDING
Generate Scaffolding

sails generate (type) <id>
model, controller, default is both
Pluggable Generators for Scaffolding
Coming

V0.10
Soon

sails generate (type) <id>
model, controller, api, blog,
user, whatever you want!
MODELS

(Waterline Collection)

api/models

var Person = {

schema : true,

attributes: {

firstName: 'string',

lastName: 'string',

password : {

type : 'string',

required : true,

notEmpty : true

},

age : {

type: 'integer',

max: 150,

required: true

},

birthDate: 'date',

phoneNumber: {

type: 'string',

defaultsTo: '111-222-3333'

},

emailAddress: {

type: 'email', // Email type will get validated by the ORM

required: true

}

}

};

model.exports = Person;
BEYOND ATTRIBUTES
// Define a custom instance method

fullName: function() {

return this.firstName + ' ' + this.lastName;

},







// Lifecycle Callbacks

beforeCreate: function(values, next) {

bcrypt.hash(values.password, 10, function(err, hash) {

if(err) return next(err);

values.password = hash;

next();

});

},

// Override toJSON instance method

// to remove phoneNumber value

toJSON: function() {

var obj = this.toObject();

delete obj.password;

return obj;

}
ORM - WATERLINE

https://github.com/balderdashy/waterline
• ActiveRecord, Hibernate, and
Mongoose
• emphasis on modularity,
testability, and consistency
across adapters
• Waterline Adapter -> DB Query
• Custom Adapter methods
Coming

ASSOCIATIONS

V0.10

Associate models across different data stores
Defining Association
var Blog = {

attributes : {

title : 'string',

body : 'string',

author : {

model : 'person'

}

}

};

Soon

Relationship Types
• One way
• One-to-One
• One-to-Many
• Many-to-Many

Blog.find({title:'Sails.js Presentation'}).populate('author').exec(console.log);
Full Sail Ahead!
RESOURCEFUL ROUTING
CRUD Routes

get /:controller/:id?	

post /:controller	

put /:controller/:id	

delete /:controller/:id

FREE
To disable set the ‘shortcuts’ flag to
false in config/controllers.js,

REST Routes

/:controller/find/:id?	

/:controller/create	

/:controller/update/:id	

/:controller/destroy/:id

FREE
!

To disable set the ‘rest’ flag to false in
config/controllers.js
CONTROLLERS
api/controllers

var ChickenController = {

// Peck the chicken specified by id (subtract 50 HP)

peck: function (req,res) {

Chicken.find(req.param('id')).exec(function (err, chicken) {

if (err) return res.send(err,500);

if (!chicken) return res.send("No other chicken with that id exists!", 404);

if (chicken.hp <= 0) return res.send("The other chicken is already dead!", 403);

chicken.hp -= 50; // Subtract 50 HP from the chicken



chicken.save(function (err) { // Persist the change

if (err) return res.send(err,500);

// Report back with the new state of the chicken

res.json(chicken);

});

});

}

};

module.exports = ChickenController;
SOCKET.IO

http://socket.io/

// all controller routes return valid responses

socket.get('/todo/count', function(results) { console.log(results) });




// create a new item

socket.post('/todo', {"title" : "this is from sockets"}, function(err,results)
{ console.log(err,results) });




// all valid ways to update with websockets

socket.put('/todo', {'id' : 1, 'title' : "updated1"}, function(results) { console.log(results) });

socket.put('/todo/1', {'title' : "updated2"}, function(results) { console.log(results) });

socket.get('/todo/update/1', {'title' : "updated3"}, function(results) { console.log(results) });




// all valid ways to delete with websockets

socket.delete('/todo', {'id' : 1}, function(results) { console.log(results) });

socket.delete('/todo/1', function(results) { console.log(results) });

socket.get('/todo/delete/21',function(results) { console.log(results)});




// listen for messages

socket.on('message', function(message) { console.log(message) });




// listen for messages from a specific controller

socket.on('todo',function(message) { console.log(message) });

Coming

V0.10
Soon
POLICIES
api/policies/isAuthenticated.js
module.exports = function(req, res, next) {

// User is allowed, proceed to the next policy, 

// or if this is the last policy, the controller

if (req.session.authorized == true) {

return next();

}




// User is not allowed

// (default res.forbidden() behavior can be overridden in `config/403.js`)

return res.forbidden('You are not permitted to perform this action.');

};

config/policies.js
module.exports.policies = {

// Default policy for all controllers and actions

// (`true` allows public access) 

'*': true,




// Policies for /Foo/* routes

FooController: {

"*" : true,

'update' : 'isAuthenticated',

'destroy' : ['isAuthenticated','isOwner']

}

};
ASSET MANAGEMENT
assets/linker/

Enabling Asset Linking

sails new <appName>

--linker

Place Assets in between special linker flags
GET STARTED BUILDING
https://github.com/cgmartin/sailsjs-angularjs-bootstrap-example

https://www.npmjs.org/package/generator-sails

http://irlnathan.github.io/sailscasts/
THANKS!

@nickmcclay

More Related Content

KEY
Node.js 0.8 features
Nicholas McClay
 
PDF
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PDF
Introduction to Nodejs
Gabriele Lana
 
PDF
What is nodejs
JeongHun Byeon
 
KEY
Node.js - Best practices
Felix Geisendörfer
 
PDF
Building servers with Node.js
ConFoo
 
PPTX
introduction to node.js
orkaplan
 
Node.js 0.8 features
Nicholas McClay
 
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Writing robust Node.js applications
Tom Croucher
 
Introduction to Nodejs
Gabriele Lana
 
What is nodejs
JeongHun Byeon
 
Node.js - Best practices
Felix Geisendörfer
 
Building servers with Node.js
ConFoo
 
introduction to node.js
orkaplan
 

What's hot (20)

PDF
Node.js - A Quick Tour
Felix Geisendörfer
 
KEY
Building a real life application in node js
fakedarren
 
KEY
A million connections and beyond - Node.js at scale
Tom Croucher
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PPTX
The State of JavaScript (2015)
Domenic Denicola
 
PDF
Ember background basics
Philipp Fehre
 
PPT
Building your first Node app with Connect & Express
Christian Joudrey
 
PDF
Comet with node.js and V8
amix3k
 
KEY
Introduction to node.js
jacekbecela
 
PDF
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PPT
Node js presentation
martincabrera
 
PDF
Express node js
Yashprit Singh
 
PPTX
Node.js Patterns for Discerning Developers
cacois
 
PDF
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
PDF
Node Architecture and Getting Started with Express
jguerrero999
 
PDF
Node.js API 서버 성능 개선기
JeongHun Byeon
 
KEY
NodeJS
.toster
 
PPTX
Java script at backend nodejs
Amit Thakkar
 
PDF
node.js Module Development
Jay Harris
 
Node.js - A Quick Tour
Felix Geisendörfer
 
Building a real life application in node js
fakedarren
 
A million connections and beyond - Node.js at scale
Tom Croucher
 
Intro to Node.js (v1)
Chris Cowan
 
The State of JavaScript (2015)
Domenic Denicola
 
Ember background basics
Philipp Fehre
 
Building your first Node app with Connect & Express
Christian Joudrey
 
Comet with node.js and V8
amix3k
 
Introduction to node.js
jacekbecela
 
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
node.js: Javascript's in your backend
David Padbury
 
Node js presentation
martincabrera
 
Express node js
Yashprit Singh
 
Node.js Patterns for Discerning Developers
cacois
 
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
Node Architecture and Getting Started with Express
jguerrero999
 
Node.js API 서버 성능 개선기
JeongHun Byeon
 
NodeJS
.toster
 
Java script at backend nodejs
Amit Thakkar
 
node.js Module Development
Jay Harris
 
Ad

Viewers also liked (11)

PDF
Node.js 淺談res tful
Simon Su
 
PDF
Node.js 台灣,社群經驗分享 201312
Caesar Chi
 
PDF
Docker 導入:障礙與對策
William Yeh
 
PDF
MakerBoard: MT7688 Emulator
Fred Chien
 
PDF
我編譯故我在:誰說 Node.js 程式不能編成 binary
Fred Chien
 
PDF
Brig:Node.js + QML 華麗大冒險
Fred Chien
 
PDF
初心者 Git 上手攻略
Lucien Lee
 
PDF
Node way
Ethan Zhang
 
PDF
從線上售票看作業系統設計議題
National Cheng Kung University
 
PDF
給學生的:seo這條路
Wanju Wang
 
PDF
PWA and Chatbot - with e-Commerce experience sharing
Caesar Chi
 
Node.js 淺談res tful
Simon Su
 
Node.js 台灣,社群經驗分享 201312
Caesar Chi
 
Docker 導入:障礙與對策
William Yeh
 
MakerBoard: MT7688 Emulator
Fred Chien
 
我編譯故我在:誰說 Node.js 程式不能編成 binary
Fred Chien
 
Brig:Node.js + QML 華麗大冒險
Fred Chien
 
初心者 Git 上手攻略
Lucien Lee
 
Node way
Ethan Zhang
 
從線上售票看作業系統設計議題
National Cheng Kung University
 
給學生的:seo這條路
Wanju Wang
 
PWA and Chatbot - with e-Commerce experience sharing
Caesar Chi
 
Ad

Similar to Intro to Sail.js (20)

PPT
Developing Rest services with SailsJs by Andrey Kolodnitskiy
Lohika_Odessa_TechTalks
 
PPT
Sails js
Andrey Kolodnitsky
 
PDF
JS Lab`16. Андрей Колодницкий: "Разработка REST сервисов на SailsJS"
GeeksLab Odessa
 
PDF
Node PDX: Intro to Sails.js
Mike McNeil
 
PDF
Intro to Sails.js
DevOpsDays Austin 2014
 
PPTX
Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js
Eric Nograles
 
KEY
Socket.io
Timothy Fitz
 
PDF
Node.js Course 2 of 2 - Advanced techniques
Manuel Eusebio de Paz Carmona
 
PPT
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
PDF
Nodejs + Rails
Michał Łomnicki
 
PDF
Real-Time with Flowdock
Flowdock
 
PPTX
Building and Scaling Node.js Applications
Ohad Kravchick
 
PPT
Server side JavaScript: going all the way
Oleg Podsechin
 
PDF
Realtime MVC with Sails.js
Serdar Dogruyol
 
PPTX
Like Ruby on Rails for Node - the Sails js framework
Stenio Ferreira
 
KEY
Practical Use of MongoDB for Node.js
async_io
 
PDF
Realtime web apps rails
Ambert Ho
 
PDF
Node.js to the rescue
Marko Heijnen
 
PDF
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
PDF
Sails.js Intro
Nicholas Jansma
 
Developing Rest services with SailsJs by Andrey Kolodnitskiy
Lohika_Odessa_TechTalks
 
JS Lab`16. Андрей Колодницкий: "Разработка REST сервисов на SailsJS"
GeeksLab Odessa
 
Node PDX: Intro to Sails.js
Mike McNeil
 
Intro to Sails.js
DevOpsDays Austin 2014
 
Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js
Eric Nograles
 
Socket.io
Timothy Fitz
 
Node.js Course 2 of 2 - Advanced techniques
Manuel Eusebio de Paz Carmona
 
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
Nodejs + Rails
Michał Łomnicki
 
Real-Time with Flowdock
Flowdock
 
Building and Scaling Node.js Applications
Ohad Kravchick
 
Server side JavaScript: going all the way
Oleg Podsechin
 
Realtime MVC with Sails.js
Serdar Dogruyol
 
Like Ruby on Rails for Node - the Sails js framework
Stenio Ferreira
 
Practical Use of MongoDB for Node.js
async_io
 
Realtime web apps rails
Ambert Ho
 
Node.js to the rescue
Marko Heijnen
 
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
Sails.js Intro
Nicholas Jansma
 

More from Nicholas McClay (6)

PDF
Node.js and Parse
Nicholas McClay
 
PPT
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
PPT
Node.js Cloud deployment
Nicholas McClay
 
PPT
Coffee script throwdown
Nicholas McClay
 
KEY
Node.js and NoSQL
Nicholas McClay
 
PPTX
Node.js debugging
Nicholas McClay
 
Node.js and Parse
Nicholas McClay
 
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
Node.js Cloud deployment
Nicholas McClay
 
Coffee script throwdown
Nicholas McClay
 
Node.js and NoSQL
Nicholas McClay
 
Node.js debugging
Nicholas McClay
 

Recently uploaded (20)

PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Software Development Methodologies in 2025
KodekX
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 

Intro to Sail.js