Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2013 Intro to Sails (v0.9.8)

2013 Intro to Sails (v0.9.8)

In this talk, I give a brief introduction to Sails.js, a realtime, server-side MVC framework for Node.js. I’ll point out some of the problems that Node.js developers face when trying to build apps from scratch, and show how Sails helps solve them. I’ll also live-code examples of some tasks that are simplified by Sails.js.

Sails is an open-source framework built on top of Express, Socket.io, and other industry-standard node modules. 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 aim is to make Node.js practical for production applications, by providing a familiar structure for an app’s back-end while remaining unopinionated about the front-end as well as database-agnostic. It’s especially good for creating realtime features, such as chat.

(Updated:)
other topics covered:
+ High-level look at associations in Sails v0.10
+ Plugins (generators, hooks, adapters, blueprints, custom responses)

Mike McNeil

May 16, 2013
Tweet

More Decks by Mike McNeil

Other Decks in Programming

Transcript

  1. We design and develop javascript apps for enterprise and startup

    customers. i have a startup called balderdash
  2. 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
  3. Realtime used to be kind of hard XMPP Comet Reverse

    AJAX Long polling Flash sockets WebSockets Server-sent events
  4. 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.
  5. 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
  6. 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.
  7. Express wasn’t “structured enough” Authentication has to be rolled from

    scratch No standard, implementation-agnostic method of working with datastores
  8. 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
  9. Lots of different kinds of projects There weren’t really any

    simple and reproducible patterns for structuring complicated Node.js aplications top to bottom
  10. 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
  11. 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
  12. MVC structure Sails.js is modeled after the same convention-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.
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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)
  18. BTTPDJBUJPOT • TIPVMEVQHSBEFOPUPOMZ8BUFSMJOF 03. CVUBMTP3&45GVMCMVFQSJOUT BOENPEFMGPDVTFEQVCMJTI TVCTDSJCF QVCTVC NFUIPET •

    DSPTTBEBQUFS • DSPTTDPOOFDUJPO • FGàDJFOUBTQPTTJCMF BMMPXJOHNPSF FGàDJFOUTPMVUJPOTUPCFJNQMFNFOUFE BUUIFBEBQUFSMBZFS Sturday, Jauary 25, 4
  19. JNQBDUPOBEBQUFST • &YJTUJOH4BJMTBEBQUFST BOEBOZ OFXPOFTZPVXSJUF OPXTVQQPSU BTTPDJBUJPOTPVUPGUIFCPY  XJUIPVUXSJUJOHBOZBEEJUJPOBM DPEF

    • :PVDBOBEEBzKPJO zNFUIPE UIBUXJMMCFVTFEJOTUFBEPG zàOE zGPSSVOOJOHJOUSB EBUBCBTFBTTPDJBUJPOTRVFSJFT
  20. CURRENT STATUS (V0..) Community is growing (almost 5000 stars, over

    400 forks on github, active IRC channel and Google group)
  21. Community is growing (almost 5000 stars, over 400 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.)
  22. My company and most of our customers are using Sails

    in production Oldest running production Sails app has been up for nearly 2 years CURRENT STATUS (V0..) Community is growing (almost 5000 stars, over 400 forks on github, active IRC channel and Google group)
  23. FYUFOEJOHTBJMT • BEBQUFSJOUFSGBDFTUBOEBSETGPSIPXPVS TFSWFSTUBMLUPEBUBCBTFTBOEXFCTFSWJDFT • CMVFQSJOUJOUFSGBDFTUBOEBSETGPSIPXPVS TFSWFSTPGGFSVQUIFJSPXO"1*TUBSUXJUI DPOWFOUJPOBMTFUVQ UIFOKVNQJOUPXSJUJOH DVTUPNDPEFMBUFS

    HFOFSBUPSTQMVHJOTUIBUBMMPX•ƒ‹Ž•‡™BOE •ƒ‹Ž•‰‡‡”ƒ–‡PVUQVUUPCFDPNQMFUFMZ PWFSSJEEFOBOEPSFYUFOEFE • IPPLTQMVHJOTUIBUBMMPXDPNQPOFOUT PGUIF4BJMTSVOUJNFUPCFPWFSSJEEFOPS FYUFOEFE •
  24. BEBQUFST • TBJMTNZTRM ſpm$install$sails*mysql) • TBJMTSFEJT ſpm$install$sails*redis) • TBJMTNPOHP ſpm$install$sails*mongo)

    • TBJMTQPTUHSFTRM ſpm$install$sails*postgresql) • TBJMTSFTU ſpm$install$sails*rest) • TBJMTNBOESJMM ſpm$install$sails*mandrill) • FUD
  25. CMVFQSJOUT • HFOFSJDJNQMGPS)551TPDLFU"1*T • QSJPSJUJ[FTVTBCJMJUZQSBDUJDBMJUZPWFSFMFHBODF • EFDMBSBUJWFDPOàHVSBUJPO FHFNCFSFYQFDUTBDFSUBJOGPSNBU PS BOHVMBSQSFGFSTBDFSUBJO+40/1QBSBNFUFS

    • PWFSSJEBCMF DBOSFQMBDFMPHJDDPNQMFUFMZXJUI JNQFSBUJWFDPEFBUBNPNFOUTOPUJDF • JOTUBMMFEWJBHFOFSBUPSTGPSOPX npm$install$sails*generate*blueprints*ember
  26. HFOFSBUPST • TBJMTHFOFSBUFOFX 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 • TBJMTHFOFSBUFCBDLFOE npm$install$sails*generate*backend*coffee

    npm$install$sails*generate*new*jade • TBJMTHFOFSBUFGSPOUFOE • TBJMTHFOFSBUFHSVOUàMF • TBJMTHFOFSBUFDPOUSPMMFS npm$install$sails*generate*controller*coffee • TBJMTHFOFSBUFBQJ • FUD
  27. IPPLT r IUUQ r TPDLFUT r PSN r DPST r

    DTSG r NJHSBUJPOT r FUD
  28. Want to get involved? Contribute to an adapter improve the

    documentation Write tutorials Blog about Sails
  29. Contribute to an adapter improve the documentation Write tutorials Blog

    about Sails Play with Sails and come up with more cool shit Want to get involved?