SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
http://www.meetup.com/Pittsburgh-Node-js/
NICHOLAS MCCLAY
UX Developer

@nickmcclay
MEET YOUR NEIGHBOR
Framework Overview
SAILS HIGHLIGHTS
• Robust Node.js MVC web server framework
!

• Railsy features - scaffolding, DB agnostic ORM
!

• Automatically generated RESTful JSON API
!

• Out-of-the-box real-time socket.io integration
!

• Role based access policies and ACL
!

• JS/CSS asset bundling and minification (Grunt)
QUICK NOTE:
Convention > Configuration = Magic
WHAT IS A
SINGLE PAGE APPLICATION?
TRADITIONAL WEB APPLICATION
http://www.cutekitties.com/kitten/1

One Kitten Please!

HTTP Request
Response
HTML
JavaScript
CSS
TADA! WEB PAGE!
SINGLE PAGE APPLICATION
http://www.cutekitties.com#/kitten/1

One Kitten Please!

HTTP Request
Application

Response
HTML
JavaScript
CSS
/kitten/1?format=json

GET /kitten/1

A JAX Request
[{

"_id" : "abc124efg345",

"lives" : 9,

"curiousity" : "massive",

"cuteness" : 9999,

"eyes" : "blue",

"fur" : "yellow"

}]

Response
JSON
TADA! WEB APP!
Heading out to sea
SAILS VERSIONS
V0.9

Coming

V0.10
V0.10

Soon

• Current NPM default

• beta version (RC3)

• Reliable starting place

• Significant Refactors

• What I’ll be demoing

• API changes

in this presentation

• Associations
• Here be dragons…

https://github.com/balderdashy/sails-docs/blob/master/Migration-Guide.md
DOCUMENTATION SOURCES
Official Website Documentation

http://sailsjs.org/#!documentation

GitHub Documentation Repo
Coming

V0.10
Soon

https://github.com/balderdashy/sails-docs/tree/0.10
CREATE A NEW SAILS PROJECT
http://sailsjs.org/#!getStarted
0.10.0 NPM INSTALL WEIRDNESS

If you encounter this, try:
npm install -g
SAILS CLI BASICS
Turn on asset linking

Make a new app

sails new <appName>
Run App

sails lift

--linker

Set Env Config

Display all logs

--dev --prod --verbose

Display Sails.js Version

sails version
SAILS SCAFFOLDING
Generate Scaffolding

sails generate (type) <id>
model, controller, default is both
Pluggable Generators for Scaffolding
Coming

V0.10
Soon

sails generate (type) <id>
model, controller, api, blog,
user, whatever you want!
MODELS

(Waterline Collection)

api/models

var Person = {

schema : true,

attributes: {

firstName: 'string',

lastName: 'string',

password : {

type : 'string',

required : true,

notEmpty : true

},

age : {

type: 'integer',

max: 150,

required: true

},

birthDate: 'date',

phoneNumber: {

type: 'string',

defaultsTo: '111-222-3333'

},

emailAddress: {

type: 'email', // Email type will get validated by the ORM

required: true

}

}

};

model.exports = Person;
BEYOND ATTRIBUTES
// Define a custom instance method

fullName: function() {

return this.firstName + ' ' + this.lastName;

},







// Lifecycle Callbacks

beforeCreate: function(values, next) {

bcrypt.hash(values.password, 10, function(err, hash) {

if(err) return next(err);

values.password = hash;

next();

});

},

// Override toJSON instance method

// to remove phoneNumber value

toJSON: function() {

var obj = this.toObject();

delete obj.password;

return obj;

}
ORM - WATERLINE

https://github.com/balderdashy/waterline
• ActiveRecord, Hibernate, and
Mongoose
• emphasis on modularity,
testability, and consistency
across adapters
• Waterline Adapter -> DB Query
• Custom Adapter methods
Coming

ASSOCIATIONS

V0.10

Associate models across different data stores
Defining Association
var Blog = {

attributes : {

title : 'string',

body : 'string',

author : {

model : 'person'

}

}

};

Soon

Relationship Types
• One way
• One-to-One
• One-to-Many
• Many-to-Many

Blog.find({title:'Sails.js Presentation'}).populate('author').exec(console.log);
Full Sail Ahead!
RESOURCEFUL ROUTING
CRUD Routes

get /:controller/:id?	

post /:controller	

put /:controller/:id	

delete /:controller/:id

FREE
To disable set the ‘shortcuts’ flag to
false in config/controllers.js,

REST Routes

/:controller/find/:id?	

/:controller/create	

/:controller/update/:id	

/:controller/destroy/:id

FREE
!

To disable set the ‘rest’ flag to false in
config/controllers.js
CONTROLLERS
api/controllers

var ChickenController = {

// Peck the chicken specified by id (subtract 50 HP)

peck: function (req,res) {

Chicken.find(req.param('id')).exec(function (err, chicken) {

if (err) return res.send(err,500);

if (!chicken) return res.send("No other chicken with that id exists!", 404);

if (chicken.hp <= 0) return res.send("The other chicken is already dead!", 403);

chicken.hp -= 50; // Subtract 50 HP from the chicken



chicken.save(function (err) { // Persist the change

if (err) return res.send(err,500);

// Report back with the new state of the chicken

res.json(chicken);

});

});

}

};

module.exports = ChickenController;
SOCKET.IO

http://socket.io/

// all controller routes return valid responses

socket.get('/todo/count', function(results) { console.log(results) });




// create a new item

socket.post('/todo', {"title" : "this is from sockets"}, function(err,results)
{ console.log(err,results) });




// all valid ways to update with websockets

socket.put('/todo', {'id' : 1, 'title' : "updated1"}, function(results) { console.log(results) });

socket.put('/todo/1', {'title' : "updated2"}, function(results) { console.log(results) });

socket.get('/todo/update/1', {'title' : "updated3"}, function(results) { console.log(results) });




// all valid ways to delete with websockets

socket.delete('/todo', {'id' : 1}, function(results) { console.log(results) });

socket.delete('/todo/1', function(results) { console.log(results) });

socket.get('/todo/delete/21',function(results) { console.log(results)});




// listen for messages

socket.on('message', function(message) { console.log(message) });




// listen for messages from a specific controller

socket.on('todo',function(message) { console.log(message) });

Coming

V0.10
Soon
POLICIES
api/policies/isAuthenticated.js
module.exports = function(req, res, next) {

// User is allowed, proceed to the next policy, 

// or if this is the last policy, the controller

if (req.session.authorized == true) {

return next();

}




// User is not allowed

// (default res.forbidden() behavior can be overridden in `config/403.js`)

return res.forbidden('You are not permitted to perform this action.');

};

config/policies.js
module.exports.policies = {

// Default policy for all controllers and actions

// (`true` allows public access) 

'*': true,




// Policies for /Foo/* routes

FooController: {

"*" : true,

'update' : 'isAuthenticated',

'destroy' : ['isAuthenticated','isOwner']

}

};
ASSET MANAGEMENT
assets/linker/

Enabling Asset Linking

sails new <appName>

--linker

Place Assets in between special linker flags
GET STARTED BUILDING
https://github.com/cgmartin/sailsjs-angularjs-bootstrap-example

https://www.npmjs.org/package/generator-sails

http://irlnathan.github.io/sailscasts/
THANKS!

@nickmcclay

Contenu connexe

Tendances

Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)Domenic Denicola
 
Ember background basics
Ember background basicsEmber background basics
Ember background basicsPhilipp Fehre
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & ExpressChristian Joudrey
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8amix3k
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsjacekbecela
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming Tom Croucher
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETGianluca Carucci
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Expressjguerrero999
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기JeongHun Byeon
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejsAmit Thakkar
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module DevelopmentJay Harris
 

Tendances (20)

Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
Ember background basics
Ember background basicsEmber background basics
Ember background basics
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Express node js
Express node jsExpress node js
Express node js
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
NodeJS
NodeJSNodeJS
NodeJS
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 

En vedette

Node.js 淺談res tful
Node.js 淺談res tfulNode.js 淺談res tful
Node.js 淺談res tfulSimon Su
 
Node.js 台灣,社群經驗分享 201312
Node.js 台灣,社群經驗分享 201312Node.js 台灣,社群經驗分享 201312
Node.js 台灣,社群經驗分享 201312Caesar Chi
 
Docker 導入:障礙與對策
Docker 導入:障礙與對策Docker 導入:障礙與對策
Docker 導入:障礙與對策William Yeh
 
MakerBoard: MT7688 Emulator
MakerBoard: MT7688 EmulatorMakerBoard: MT7688 Emulator
MakerBoard: MT7688 EmulatorFred Chien
 
我編譯故我在:誰說 Node.js 程式不能編成 binary
我編譯故我在:誰說 Node.js 程式不能編成 binary我編譯故我在:誰說 Node.js 程式不能編成 binary
我編譯故我在:誰說 Node.js 程式不能編成 binaryFred Chien
 
Brig:Node.js + QML 華麗大冒險
Brig:Node.js + QML 華麗大冒險Brig:Node.js + QML 華麗大冒險
Brig:Node.js + QML 華麗大冒險Fred Chien
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
給學生的:seo這條路
給學生的:seo這條路給學生的:seo這條路
給學生的:seo這條路Wanju Wang
 
PWA and Chatbot - with e-Commerce experience sharing
PWA and Chatbot - with e-Commerce experience sharingPWA and Chatbot - with e-Commerce experience sharing
PWA and Chatbot - with e-Commerce experience sharingCaesar Chi
 

En vedette (11)

Node.js 淺談res tful
Node.js 淺談res tfulNode.js 淺談res tful
Node.js 淺談res tful
 
Node.js 台灣,社群經驗分享 201312
Node.js 台灣,社群經驗分享 201312Node.js 台灣,社群經驗分享 201312
Node.js 台灣,社群經驗分享 201312
 
Docker 導入:障礙與對策
Docker 導入:障礙與對策Docker 導入:障礙與對策
Docker 導入:障礙與對策
 
MakerBoard: MT7688 Emulator
MakerBoard: MT7688 EmulatorMakerBoard: MT7688 Emulator
MakerBoard: MT7688 Emulator
 
我編譯故我在:誰說 Node.js 程式不能編成 binary
我編譯故我在:誰說 Node.js 程式不能編成 binary我編譯故我在:誰說 Node.js 程式不能編成 binary
我編譯故我在:誰說 Node.js 程式不能編成 binary
 
Brig:Node.js + QML 華麗大冒險
Brig:Node.js + QML 華麗大冒險Brig:Node.js + QML 華麗大冒險
Brig:Node.js + QML 華麗大冒險
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Node way
Node wayNode way
Node way
 
從線上售票看作業系統設計議題
從線上售票看作業系統設計議題從線上售票看作業系統設計議題
從線上售票看作業系統設計議題
 
給學生的:seo這條路
給學生的:seo這條路給學生的:seo這條路
給學生的:seo這條路
 
PWA and Chatbot - with e-Commerce experience sharing
PWA and Chatbot - with e-Commerce experience sharingPWA and Chatbot - with e-Commerce experience sharing
PWA and Chatbot - with e-Commerce experience sharing
 

Similaire à Intro to Sail.js

case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxtidwellveronique
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...BizTalk360
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Laravel dokumentacja Restful API - swagger
Laravel dokumentacja Restful API - swaggerLaravel dokumentacja Restful API - swagger
Laravel dokumentacja Restful API - swaggerLaravel Poland MeetUp
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLAll Things Open
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Pieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React NativePieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React Nativetlv-ios-dev
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationNordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationRouven Weßling
 

Similaire à Intro to Sail.js (20)

case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Laravel dokumentacja Restful API - swagger
Laravel dokumentacja Restful API - swaggerLaravel dokumentacja Restful API - swagger
Laravel dokumentacja Restful API - swagger
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQL
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Pieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React NativePieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React Native
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API DocumentationNordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API Documentation
 

Plus de Nicholas McClay

Plus de Nicholas McClay (6)

Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Get MEAN! Node.js and the MEAN stack
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
 
Node.js Cloud deployment
Node.js Cloud deploymentNode.js Cloud deployment
Node.js Cloud deployment
 
Coffee script throwdown
Coffee script throwdownCoffee script throwdown
Coffee script throwdown
 
Node.js and NoSQL
Node.js and NoSQLNode.js and NoSQL
Node.js and NoSQL
 
Node.js debugging
Node.js debuggingNode.js debugging
Node.js debugging
 

Dernier

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Dernier (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Intro to Sail.js

  • 5. SAILS HIGHLIGHTS • Robust Node.js MVC web server framework ! • Railsy features - scaffolding, DB agnostic ORM ! • Automatically generated RESTful JSON API ! • Out-of-the-box real-time socket.io integration ! • Role based access policies and ACL ! • JS/CSS asset bundling and minification (Grunt)
  • 6. QUICK NOTE: Convention > Configuration = Magic
  • 7. WHAT IS A SINGLE PAGE APPLICATION?
  • 16. [{
 "_id" : "abc124efg345",
 "lives" : 9,
 "curiousity" : "massive",
 "cuteness" : 9999,
 "eyes" : "blue",
 "fur" : "yellow"
 }] Response JSON
  • 19. SAILS VERSIONS V0.9 Coming V0.10 V0.10 Soon • Current NPM default • beta version (RC3) • Reliable starting place • Significant Refactors • What I’ll be demoing • API changes in this presentation • Associations • Here be dragons… https://github.com/balderdashy/sails-docs/blob/master/Migration-Guide.md
  • 20. DOCUMENTATION SOURCES Official Website Documentation http://sailsjs.org/#!documentation GitHub Documentation Repo Coming V0.10 Soon https://github.com/balderdashy/sails-docs/tree/0.10
  • 21. CREATE A NEW SAILS PROJECT http://sailsjs.org/#!getStarted
  • 22. 0.10.0 NPM INSTALL WEIRDNESS If you encounter this, try: npm install -g
  • 23. SAILS CLI BASICS Turn on asset linking Make a new app sails new <appName> Run App sails lift --linker Set Env Config Display all logs --dev --prod --verbose Display Sails.js Version sails version
  • 24. SAILS SCAFFOLDING Generate Scaffolding sails generate (type) <id> model, controller, default is both Pluggable Generators for Scaffolding Coming V0.10 Soon sails generate (type) <id> model, controller, api, blog, user, whatever you want!
  • 25. MODELS (Waterline Collection) api/models var Person = {
 schema : true,
 attributes: {
 firstName: 'string',
 lastName: 'string',
 password : {
 type : 'string',
 required : true,
 notEmpty : true
 },
 age : {
 type: 'integer',
 max: 150,
 required: true
 },
 birthDate: 'date',
 phoneNumber: {
 type: 'string',
 defaultsTo: '111-222-3333'
 },
 emailAddress: {
 type: 'email', // Email type will get validated by the ORM
 required: true
 }
 }
 };
 model.exports = Person;
  • 26. BEYOND ATTRIBUTES // Define a custom instance method
 fullName: function() {
 return this.firstName + ' ' + this.lastName;
 },
 
 
 // Lifecycle Callbacks
 beforeCreate: function(values, next) {
 bcrypt.hash(values.password, 10, function(err, hash) {
 if(err) return next(err);
 values.password = hash;
 next();
 });
 },
 // Override toJSON instance method
 // to remove phoneNumber value
 toJSON: function() {
 var obj = this.toObject();
 delete obj.password;
 return obj;
 }
  • 27. ORM - WATERLINE https://github.com/balderdashy/waterline • ActiveRecord, Hibernate, and Mongoose • emphasis on modularity, testability, and consistency across adapters • Waterline Adapter -> DB Query • Custom Adapter methods
  • 28. Coming ASSOCIATIONS V0.10 Associate models across different data stores Defining Association var Blog = {
 attributes : {
 title : 'string',
 body : 'string',
 author : {
 model : 'person'
 }
 }
 }; Soon Relationship Types • One way • One-to-One • One-to-Many • Many-to-Many Blog.find({title:'Sails.js Presentation'}).populate('author').exec(console.log);
  • 30. RESOURCEFUL ROUTING CRUD Routes get /:controller/:id? post /:controller put /:controller/:id delete /:controller/:id FREE To disable set the ‘shortcuts’ flag to false in config/controllers.js, REST Routes /:controller/find/:id? /:controller/create /:controller/update/:id /:controller/destroy/:id FREE ! To disable set the ‘rest’ flag to false in config/controllers.js
  • 31. CONTROLLERS api/controllers var ChickenController = {
 // Peck the chicken specified by id (subtract 50 HP)
 peck: function (req,res) {
 Chicken.find(req.param('id')).exec(function (err, chicken) {
 if (err) return res.send(err,500);
 if (!chicken) return res.send("No other chicken with that id exists!", 404);
 if (chicken.hp <= 0) return res.send("The other chicken is already dead!", 403);
 chicken.hp -= 50; // Subtract 50 HP from the chicken
 
 chicken.save(function (err) { // Persist the change
 if (err) return res.send(err,500);
 // Report back with the new state of the chicken
 res.json(chicken);
 });
 });
 }
 };
 module.exports = ChickenController;
  • 32. SOCKET.IO http://socket.io/ // all controller routes return valid responses
 socket.get('/todo/count', function(results) { console.log(results) });
 
 // create a new item
 socket.post('/todo', {"title" : "this is from sockets"}, function(err,results) { console.log(err,results) });
 
 // all valid ways to update with websockets
 socket.put('/todo', {'id' : 1, 'title' : "updated1"}, function(results) { console.log(results) });
 socket.put('/todo/1', {'title' : "updated2"}, function(results) { console.log(results) });
 socket.get('/todo/update/1', {'title' : "updated3"}, function(results) { console.log(results) });
 
 // all valid ways to delete with websockets
 socket.delete('/todo', {'id' : 1}, function(results) { console.log(results) });
 socket.delete('/todo/1', function(results) { console.log(results) });
 socket.get('/todo/delete/21',function(results) { console.log(results)});
 
 // listen for messages
 socket.on('message', function(message) { console.log(message) });
 
 // listen for messages from a specific controller
 socket.on('todo',function(message) { console.log(message) }); Coming V0.10 Soon
  • 33. POLICIES api/policies/isAuthenticated.js module.exports = function(req, res, next) {
 // User is allowed, proceed to the next policy, 
 // or if this is the last policy, the controller
 if (req.session.authorized == true) {
 return next();
 }
 
 // User is not allowed
 // (default res.forbidden() behavior can be overridden in `config/403.js`)
 return res.forbidden('You are not permitted to perform this action.');
 }; config/policies.js module.exports.policies = {
 // Default policy for all controllers and actions
 // (`true` allows public access) 
 '*': true,
 
 // Policies for /Foo/* routes
 FooController: {
 "*" : true,
 'update' : 'isAuthenticated',
 'destroy' : ['isAuthenticated','isOwner']
 }
 };
  • 34. ASSET MANAGEMENT assets/linker/ Enabling Asset Linking sails new <appName> --linker Place Assets in between special linker flags