node pdx: intro to sails.js
DESCRIPTION
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.TRANSCRIPT
![Page 1: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/1.jpg)
sails.jsrealtime MVC framework for Node.js
![Page 2: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/2.jpg)
who am i?@mikermcneil
![Page 3: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/3.jpg)
Design and develop javascript apps for
enterprise and startup customers
i have a startup called balderdash
![Page 4: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/4.jpg)
Realtime used to be kind of hard
XMPPComet
Reverse AJAXLong polling
Flash socketsWebSockets
Server-sent events
![Page 5: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/5.jpg)
love at !rst sightcirca 2011
Node.js...
![Page 6: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/6.jpg)
A lot easier now
![Page 7: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/7.jpg)
Can we use Node.js for, like, everything?
i wondered...
![Page 8: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/8.jpg)
Can we use Node.js for, like, everything?
i wondered...
maybe.
![Page 9: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/9.jpg)
Lots of different
kinds of projects
There weren’t really any simple and reproducible patterns for structuring complicated Node.js aplications top to bottom
![Page 10: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/10.jpg)
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
![Page 11: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/11.jpg)
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
![Page 12: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/12.jpg)
Programming realtime apps
was still not trivial.
Socket.io and Express messages/requests have to be handled independently, which leads to separate code bases for realtime and traditional server code.
![Page 13: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/13.jpg)
Programming realtime apps
was still not trivial.
Socket.io and Express 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
![Page 14: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/14.jpg)
Socket.io and Express 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.
![Page 15: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/15.jpg)
Express wasn’t “structured
enough”
Authentication has to be rolled from scratch
![Page 16: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/16.jpg)
Express wasn’t “structured
enough”
Authentication has to be rolled from scratch
No standard, implementation-agnostic method of working with datastores
![Page 17: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/17.jpg)
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-con!guration frameworks
![Page 18: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/18.jpg)
too bad.we went with Node anyway.
![Page 19: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/19.jpg)
so Sails.js was born
![Page 20: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/20.jpg)
MVC structureSails.js is modeled after the same convetion-over-con!guration philosophy you’re used to from frameworks like Rails, Grails, Symfony, and Zend.
Controllers 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.
![Page 21: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/21.jpg)
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
![Page 22: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/22.jpg)
PoliciesPolicies 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
![Page 23: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/23.jpg)
![Page 24: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/24.jpg)
Socket.io Express 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 con!guration
![Page 25: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/25.jpg)
![Page 26: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/26.jpg)
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
![Page 27: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/27.jpg)
Other cool stuff
CLI tool
REPL
Custom adapters
Optional server-side coffee support
Automatic asset bundling (LESS and coffeescript !les are compiled, merged with css and js, and injected into the DOM, mini!ed in production mode)
![Page 28: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/28.jpg)
![Page 29: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/29.jpg)
![Page 30: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/30.jpg)
let’s code things now
OK
![Page 31: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/31.jpg)
Community is growing (1900 stars, 160 forks on github, active IRC channel and Google
group)
CURRENT STATUS (V0.8.9)
![Page 32: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/32.jpg)
Community is growing (1900 stars, 160 forks on github, active IRC channel and Google
group)
My company and most of our customers are using Sails in production
CURRENT STATUS (V0.8.9)
![Page 33: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/33.jpg)
Community is growing (1900 stars, 160 forks on github, active IRC channel and Google
group)
My company and most of our customers are using Sails in production
Oldest running production Sails app has been up for over 300 days
CURRENT STATUS (V0.8.9)
![Page 34: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/34.jpg)
Roadmap
More adapters
More modularization to allow for a la carte usage of framework components
Grunt/Yeoman integration for asset management and app generation
Built-in support for associations in ORM
![Page 35: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/35.jpg)
Contribute to an adapter
Want to get involved?
![Page 36: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/36.jpg)
Contribute to an adapter
Work on the yeoman/grunt integration
Want to get involved?
![Page 37: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/37.jpg)
Contribute to an adapter
Work on the yeoman/grunt integration
Play with Sails and come up with more cool shit
Want to get involved?
![Page 38: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/38.jpg)
Questions?
![Page 39: Node PDX: Intro to Sails.js](https://reader035.vdocuments.mx/reader035/viewer/2022062513/554bba4db4c9053a298b4c4e/html5/thumbnails/39.jpg)
Special thanks to:@colinwren
@dcbartlett
@particlebanana
@tedkulp
Irl Nathan
Troy & NodePDX
Dan Dwyer & Joyent
& all the other excellent Sails.js contributors