Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 yo...
route&
first*
philosophy
opt&in*
framework*
structure
“smalltalk*
ethics”
UML
“javascript*
ethics”
servlets
mvc
spring,*
e...
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, w...
Programming
realtime apps
was still not
trivial.
WebSocket and HTTP messages/
requests have to be handled
independently, w...
WebSocket and HTTP messages/
requests have to be handled
independently, which leads to
separate code bases for
realtime an...
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 metho...
Express wasn’t
“structured
enough”
Authentication has to be rolled
from scratch
No standard,
implementation-agnostic metho...
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated ...
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated ...
Lots
of different
kinds of
projects
There weren’t really any simple
and reproducible patterns for
structuring complicated ...
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 l...
Lightweight ORM
Kept querying semantics dead-simple and
adapter-agnostic whenever possible
Pulled the best of Active Recor...
Policies
Policies are just more Express middleware
They can be chained together to “protect”
or preprocess requests for co...
Socket.io Request
interpreter
Translated incoming socket.io messages into
Express requests
Translated res.send(), res.json...
Blueprints
Instead of something like Rails HTML
scaffolds, by default, when you generate a
model and controller, Sails ser...
Other
cool
stuff
CLI tool
REPL
Custom adapters
Optional server-side coffee
support
Automatic asset bundling (LESS
and coff...
associations
• should upgrade not only Waterline
(ORM), but also RESTful blueprints
and model-focused publish/
subscribe (...
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. ...
how it works
• when possible, use native
optimizations (i.e. joins) at the
database layer
• in-memory joins for the rest, ...
impact on adapters
• Existing Sails adapters (and any
new ones you write) now support
associations out of the box,
without...
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 gr...
Community is flourishing (over 6000 stars /
600 forks on github, active IRC channel and
Google group)
My company and most ...
My company and most of our customers are
using Sails in production
Oldest running production Sails apps
havs been up for o...
extending sails
• adapter interface: standards for how our
servers talk to databases and web services
• blueprint interfac...
adapters
• sails-mysql (npm$install$sails*mysql)
• sails-redis (npm$install$sails*redis)
• sails-mongo (npm$install$sails*...
blueprints
• generic impl. for HTTP/ socket APIs
• prioritizes usability / practicality over elegance
• declarative configu...
generators
• sails-generate-new
npm$install$sails*generate*new
npm$install$sails*generate*new*coffee
npm$install$sails*gen...
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...
Questions?
Thanks!
@mikermcneil
mike@balderdash.co
Upcoming SlideShare
Loading in …5
×

Intro to Sails.js

2,409 views

Published on

Presented at DevOpsDays Austin 2014 by Mike McNeil (http://www.slideshare.net/michaelrmcneil).

Published in: Technology
  • Be the first to comment

Intro to Sails.js

  1. 1. sails.js realtime MVC framework for Node.js
  2. 2. who am i? @mikermcneil
  3. 3. We design and develop javascript apps for enterprise and startup customers. i have a startup called balderdash
  4. 4. love at first sight circa 2011 Node.js...
  5. 5. 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) • • • • •
  6. 6. 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
  7. 7. Can we use Node.js for, like, everything? i wondered...
  8. 8. Can we use Node.js for, like, everything? i wondered... maybe.
  9. 9. Realtime used to be kind of hard XMPP Comet Reverse AJAX Long polling Flash sockets WebSockets Server-sent events
  10. 10. A lot easier now
  11. 11. 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.
  12. 12. 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
  13. 13. 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.
  14. 14. Express wasn’t “structured enough” Authentication has to be rolled from scratch
  15. 15. Express wasn’t “structured enough” Authentication has to be rolled from scratch No standard, implementation-agnostic method of working with datastores
  16. 16. 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
  17. 17. Lots of different kinds of projects There weren’t really any simple and reproducible patterns for structuring complicated Node.js aplications top to bottom
  18. 18. 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
  19. 19. 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
  20. 20. too bad. we went with Node anyway.
  21. 21. so Sails.js was born
  22. 22. 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.
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. 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.
  28. 28. 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
  29. 29. why mess with this? • NoSQL • simplicity • performance • traditional SQL databases • built-in ACID • reporting queries
  30. 30. cross-adapter • MySQL tables • MongoDB collections • PostgreSQL tables • Twitter API REST resources • etc.
  31. 31. cross-connection • different hosts (servers) • different database users • nasty/annoying integrations w/ legacy data e.g. join two different MySQL databases with incompatible schemas •
  32. 32. 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
  33. 33. 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.
  34. 34. let’s code things now OK
  35. 35. CURRENT STATUS (V0.9.13) Community is flourishing (over 6000 stars / 600 forks on github, active IRC channel and Google group)
  36. 36. 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)
  37. 37. 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)
  38. 38. 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 •
  39. 39. 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.
  40. 40. 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)
  41. 41. 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.
  42. 42. hooks • http • sockets • orm • cors • csrf • spdy • etc.
  43. 43. Want to get involved? Contribute to an adapter
  44. 44. Want to get involved? Contribute to an adapter improve the documentation
  45. 45. Want to get involved? Contribute to an adapter improve the documentation Write tutorials
  46. 46. Want to get involved? Contribute to an adapter Improve the documentation Write tutorials Blog about Sails
  47. 47. 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?
  48. 48. Questions?
  49. 49. Thanks! @mikermcneil mike@balderdash.co

×