A slideshow introducing Sails.js as an MVC style framework for Node.js Web API's. Goes over key Sails features and an opinion of "enterprise-style" separation of concerns familiar to ASP .Net MVC and Spring MVC developers. Presented by Eric Nograles @ Orlando Code Camp on March 28, 2015.
6. Meet Sails!
• Full MVC framework on Node.js and Express
• Can be used in request/response web or Web
API capacity
• Integrated, curated libraries
• Wide community support
7. The Sails Way
• Stay true to Node.js/Express development
• Convention over configuration, but not to the
point of “dark magic”
• “Just enough” framework
9. A 3 Hour 40 Minute Tour
• Routing/Policies
• Waterline ORM
• WebSockets pub/sub using socket.io
• Separation of Concerns
• Unit Testing
10. Routing/Policies
• Conventions
• /controllers/ExampleController.someAction =
/example/someAction
• If a corresponding model is defined, RESTful routes enabled
• Controller Actions: find/findOne, create, update, destroy
• Policies defined in /config/policies.js (which uses /api/policies) are enforced
• Features
• Express-style routes
• Route conventions highly configurable
11. • Conventions
• Globally accessible in Sails
• Uses default connection defined in /config/models.js and
/config/connections.js
• Model connections and settings are overridable
• Features
• Schema enforcement
• Lifecycle callbacks (events after create, update, destroy)
12. Pub/Sub
• Conventions
• WebSockets globally accessible via sails.io.sockets
• All WebSocket settings defined by
/config/sockets.js
• Features
• Socket.io client readily available from startup
• Distributed pub/sub capability (via redis)
13. Great tools and all
But, how do we make this enterprise grade?
16. Unit Testing
• Mocha: a JavaScript unit testing framework
• Integrates seamlessly with WebStorm
• Proxyquire: mock require dependencies
• Grunt: Automated task runner for tests, integrates
with CI
17. Install grunt-mocha-test from NPM
Establish test.js under /tasks,
configure mochaTest to run
tests/**/*.spec.js.
Establish a /tests folder. Follow the structure
of the /api folder
Author some unit tests using *.spec.js
naming convention. Use proxyquire to
inject require modules where applicable.
Run grunt mochaTest
19. Avast!
• It’s a full MVC solution on Node.js! Yay!
• Sails offers enough convention to increase your
development velocity…
• …but, also offers enough configuration to
handle project realities
• Enterprise patterns translate well to Sails