SlideShare a Scribd company logo
1 of 49
Download to read offline
sails.js
realtime MVC framework for Node.js
who am i?
@mikermcneil
We design and develop javascript apps for
enterprise and startup customers.
i have a startup called balderdash
love at first sight
circa 2011
Node.js...
node.js translates server concepts into
javascript-- the lingua franca for the every-
man
our event loop is faster than your thing
native bindings means Node can do pretty
much anything
core is purposefully feature-sparse
npm publish, nuff said (lower barrier to
entry)
•
•
•
•
•
route&
first*
philosophy
opt&in*
framework*
structure
“smalltalk*
ethics”
UML
“javascript*
ethics”
servlets
mvc
spring,*
et.*al.
rails
enterprise*
java
ruby
module
system
(npm)
noSQL
(mongo/
redis)
async*
flow*
control
from*the*
front&end:
generators
(yeoman)
node.js
convention*
over*
configuration
event*loop
ORM
Can we use Node.js for,
like, everything?
i wondered...
Can we use Node.js for,
like, everything?
i wondered...
maybe.
Realtime used to
be kind of hard
XMPP
Comet
Reverse AJAX
Long polling
Flash sockets
WebSockets
Server-sent events
A lot easier now
Programming
realtime apps
was still not
trivial.
WebSocket and HTTP messages/
requests have to be handled
independently, which leads to
separate code bases for
realtime and traditional server
code.
Programming
realtime apps
was still not
trivial.
WebSocket and HTTP messages/
requests have to be handled
independently, which leads to
separate code bases for
realtime and traditional server
code.
Socket programming is a new
paradigm for many modern web
developers
WebSocket and HTTP messages/
requests have to be handled
independently, which leads to
separate code bases for
realtime and traditional server
code.
Socket programming is a new
paradigm for many modern web
developers
Questions about scalability
Programming
realtime apps
was still not
trivial.
Express wasn’t
“structured
enough”
Authentication has to be rolled
from scratch
Express wasn’t
“structured
enough”
Authentication has to be rolled
from scratch
No standard,
implementation-agnostic method
of working with datastores
Express wasn’t
“structured
enough”
Authentication has to be rolled
from scratch
No standard,
implementation-agnostic method
of working with datastores
Low level and free-form -- not a
lot of guidelines for teams used
to convention-over-configuration
frameworks
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated Node.js
aplications top to bottom
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated Node.js
aplications top to bottom
Could be working with an
existing client, or writing a new
client for a mobile web browser,
an automobile, a toaster, or god
knows what
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated Node.js
aplications top to bottom
Could be working with an
existing client, or writing a new
client for a mobile web browser,
an automobile, a toaster, or god
knows what
Lots of different 3rd party
proprietary services to deal with
on the back-end -- there was no
standard way to integrate new
systems
too bad.
we went with Node anyway.
so Sails.js was born
MVC structure
Sails.js is modeled after the same
convention-over-configuration philosophy
you’re used to from frameworks like Rails,
Grails, Symfony, and Zend.
Controller actions are just Express middleware
Views are ejs by default, but you can use
jade, etc. We rarely use them since we’re
normally making single page apps with
client-side templates.
Lightweight ORM
Kept querying semantics dead-simple and
adapter-agnostic whenever possible
Pulled the best of Active Record,
Hibernate, and Mongoose
Made it easy to add purpose-built adapters
at the app level
Policies
Policies are just more Express middleware
They can be chained together to “protect”
or preprocess requests for controllers
E.g. access control, storage quotas, or
anything else you’d want to use
middleware for
Socket.io Request
interpreter
Translated incoming socket.io messages into
Express requests
Translated res.send(), res.json(), and res.view()
to respond via the socket, as well as allowing
for streams
Added res.broadcast() and req.join() methods
for pubsub
Normalized configuration
Blueprints
Instead of something like Rails HTML
scaffolds, by default, when you generate a
model and controller, Sails serves an API
Built-in search, sort, pagination, and
complex queries
Authentication/access control can be built
on top using policies
Other
cool
stuff
CLI tool
REPL
Custom adapters
Optional server-side coffee
support
Automatic asset bundling (LESS
and coffeescript files are
compiled, merged with css and js,
and injected into the DOM,
minified in production mode)
Uses grunt by default, but can be
replaced by ant, gulp, maven,
etc.
associations
• should upgrade not only Waterline
(ORM), but also RESTful blueprints
and model-focused publish/
subscribe (pubsub) methods.
• cross-adapter
• cross-connection
• efficient as possible, allowing more
efficient solutions to be implemented
at the adapter layer
Sturday, Jauary 25, 4
why mess with this?
• NoSQL
• simplicity
• performance
• traditional SQL databases
• built-in ACID
• reporting queries
cross-adapter
• MySQL tables
• MongoDB collections
• PostgreSQL tables
• Twitter API REST resources
• etc.
cross-connection
• different hosts (servers)
• different database users
• nasty/annoying integrations w/
legacy data
e.g. join two different MySQL
databases with incompatible
schemas
•
how it works
• when possible, use native
optimizations (i.e. joins) at the
database layer
• in-memory joins for the rest, just
like you would have to do in code
• maintains multiple connection pools
impact on adapters
• Existing Sails adapters (and any
new ones you write) now support
associations out of the box,
without writing any additional
code.
• You can add a `join()` method
that will be used instead of
`find()` for running intra-
database associations queries.
let’s code things now
OK
CURRENT STATUS (V0.9.13)
Community is flourishing (over 6000 stars /
600 forks on github, active IRC channel and
Google group)
Community is flourishing (over 6000 stars /
600 forks on github, active IRC channel and
Google group)
My company and most of our customers are
using Sails in production
CURRENT STATUS (V0.9.13)
My company and most of our customers are
using Sails in production
Oldest running production Sails apps
havs been up for over 2 years
CURRENT STATUS (V0.9.13)
Community is flourishing (over 6000 stars /
600 forks on github, active IRC channel and
Google group)
extending sails
• adapter interface: standards for how our
servers talk to databases and web services
• blueprint interface: standards for how our
servers offer up their own API-- start with
conventional setup, then jump into writing
custom code later.
generators: plugins that allow sails new and
sails generate output to be completely
overridden and/or extended
• hooks: plugins that allow components
of the Sails runtime to be overridden or
extended
•
adapters
• sails-mysql (npm$install$sails*mysql)
• sails-redis (npm$install$sails*redis)
• sails-mongo (npm$install$sails*mongo)
• sails-postgresql (npm$install$sails*postgresql)
• sails-rest (npm$install$sails*rest)
• sails-couch (npm$install$sails*couch)
• etc.
blueprints
• generic impl. for HTTP/ socket APIs
• prioritizes usability / practicality over elegance
• declarative configuration
(e.g. ember expects a certain format, or
angular prefers a certain JSONP parameter)
• overridable
(can replace logic completely with
imperative code at a moment’s notice)
generators
• sails-generate-new
npm$install$sails*generate*new
npm$install$sails*generate*new*coffee
npm$install$sails*generate*new*but*like*express
npm$install$sails*generate*new*blog
• sails-generate-backend
npm$install$sails*generate*backend*coffee
npm$install$sails*generate*new*jade
• sails-generate-frontend
• sails-generate-gruntfile
• sails-generate-controller
npm$install$sails*generate*controller*coffee
• sails-generate-auth
• etc.
hooks
• http
• sockets
• orm
• cors
• csrf
• spdy
• etc.
Want to get involved?
Contribute to an adapter
Want to get involved?
Contribute to an adapter
improve the documentation
Want to get involved?
Contribute to an adapter
improve the documentation
Write tutorials
Want to get involved?
Contribute to an adapter
Improve the documentation
Write tutorials
Blog about Sails
Contribute to an adapter
improve the documentation
Write tutorials
Blog about Sails
Build an integration with your
product or API (it's pretty easy)
Want to get involved?
Questions?
Thanks!
@mikermcneil
mike@balderdash.co

More Related Content

What's hot

Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
Fabrice Hong
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScript
Spike Brehm
 

What's hot (20)

CQ5 and Sling overview
CQ5 and Sling overviewCQ5 and Sling overview
CQ5 and Sling overview
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
An Overview on Nuxt.js
An Overview on Nuxt.jsAn Overview on Nuxt.js
An Overview on Nuxt.js
 
Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
 
Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
 
Nuxt Talk
Nuxt TalkNuxt Talk
Nuxt Talk
 
Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require js
 
Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Require js
Require jsRequire js
Require js
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
 
Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScript
 
Drupal & AngularJS - DrupalCamp Spain 2014
Drupal & AngularJS - DrupalCamp Spain 2014Drupal & AngularJS - DrupalCamp Spain 2014
Drupal & AngularJS - DrupalCamp Spain 2014
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 

Similar to Intro to Sails.js

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 

Similar to Intro to Sails.js (20)

What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Node js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsNode js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share ppts
 
Node js
Node jsNode js
Node js
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
Nodejs
NodejsNodejs
Nodejs
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
NodeJS and what is actually does
NodeJS and what is actually doesNodeJS and what is actually does
NodeJS and what is actually does
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
LoopbackJS the intro
LoopbackJS the introLoopbackJS the intro
LoopbackJS the intro
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
The MEAN Stack
The MEAN StackThe MEAN Stack
The MEAN Stack
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Intro to Sails.js