come sail away with me (you guys): node.js mvc web api's using sails.js
Post on 16-Jul-2015
813 Views
Preview:
TRANSCRIPT
Eric Nograles
Software Developer (352 Inc.)
Email: grales@gmail.com
Twitter: @grales
GitHub:
https://github.com/ericnograles
LinkedIn:
https://www.linkedin.com/in/ericn
ograles
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
The Sails Way
• Stay true to Node.js/Express development
• Convention over configuration, but not to the
point of “dark magic”
• “Just enough” framework
A 3 Hour 40 Minute Tour
• Routing/Policies
• Waterline ORM
• WebSockets pub/sub using socket.io
• Separation of Concerns
• Unit Testing
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
• 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)
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)
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
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
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
GitHub Goodies!
• https://github.com/ericnograles/DeepThought
• master: Close to “out-of-the-box” Sails
• repositoryPattern: master + repo pattern
• fullEnterprise: Full n-tiered architecture,
with a redis application cache
top related