Top Banner
Come Sail Away With Me *you guys* Node.js MVC Web API’s Using Sails.js
21

Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Jul 16, 2015

Download

Technology

Eric Nograles
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Come Sail Away With Me*you guys*

Node.js MVC Web API’s Using Sails.js

Page 2: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Eric Nograles

Software Developer (352 Inc.)

Email: [email protected]

Twitter: @grales

GitHub:

https://github.com/ericnograles

LinkedIn:

https://www.linkedin.com/in/ericn

ograles

Page 3: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

My 2014A JavaScript Vision Quest

Page 4: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

The Result…Proxy.gg (https://www.proxy.gg)

Page 5: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

SailsOur Web API Weapon of Choice

Page 6: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 7: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

The Sails Way

• Stay true to Node.js/Express development

• Convention over configuration, but not to the

point of “dark magic”

• “Just enough” framework

Page 8: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

A working WebAPI in under 1 minute

Don’t believe me, just watch.

Page 9: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

A 3 Hour 40 Minute Tour

• Routing/Policies

• Waterline ORM

• WebSockets pub/sub using socket.io

• Separation of Concerns

• Unit Testing

Page 10: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 11: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

• 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)

Page 12: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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)

Page 13: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Great tools and allBut, how do we make this enterprise grade?

Page 14: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Separation of Concerns: A

Classical Approach

Page 15: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Separation of Concerns:

Sails.js

Page 16: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 17: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 18: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

WebStorm Integration

Page 19: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 20: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

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

Page 21: Come Sail Away With Me (you guys): Node.js MVC Web API's Using Sails.js

Thanks!

_.each(attendees, function(attendee) {

eric.highFive(attendee);

});