SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
POP
Behind the sense
About me
Ben Lin
Co-founder at WOOMOO INC.
A full time entrepreneur & JavaScript lover
Fall in love with node.js on Jun 2011




                                                      dreamerslab.com
                                               ben@dreamerslab.com
                                              twitter.com/dreamerslab
                                              github.com/dreamerslab
About me

   COKE - Full stack node.js MVC framework
   Vodka - Functional testing framework
   Thunder - The lightning fast template engine


   And a lot more on
   https://github.com/dreamerslab
Agenda

         1. Software architecture
         2. Frameworks & Libraries
         3. Application stack
         4. Packages
         5. Scaling node.js
         6. Deployment
         7. Q & A
Software architecture
Software architecture


     Home brewed node.js MVC framework - COKE


              Why node.js?
             It’s fast and easy to scale horizontally
Software architecture
Restful router for api & web server



          module.exports = function ( map ){
            map.get( 'api', 'api/home#index' );
            map.namespace( 'api', function ( api ){
              api.resources( 'users', {
                only : [ 'create', 'show', 'update', 'destroy' ]
              }, function ( users ){
                users.get( 'projects/:id/full', 'user_projects#full' );
                users.resources( 'user_projects', {
                  path : 'projects',
                  only : [ 'create', 'index', 'show', 'update', 'destroy' ]
                });

                 // more routes ......
               });
          };
Software architecture
Validation   make sure all the arguments are correct before get into controllers



                  var form = require( 'express-form2' );
                  var field = form.field;
                  var r     = require( '../regex' );

                  module.exports = {

                       validate_create : form(
                          field( 'client_id' ).required().is( r.id, '01' ),
                          field( 'mockup_id' ).required().is( r.id, '01' ),
                          field( 'format' ).required().is( r.img, '014' )
                       ),

                       validate_index : form(
                          field( 'mockup_id' ).required().is( r.id, '01' )
                       ),

                       validate_destroy : form(
                         field( 'mockup_id' ).required().is( r.id, '01' ),
                         field( 'id' ).required().is( r.id, '01' )
                       )
                  };
Software architecture
Controller Only do data exchange & flow control

                       module.exports = Application.extend({

                         init : function ( before, after ){
                            before( this.is_authenticated );
                            before( this.validate_create );
                            before( this.has_file );
                            before( this.is_validate );
                         },

                         create : function ( req, res, next ){
                           var self = this;

                             ProjectImage.insert( req.form, next,
                               function (){
                                  self.forbidden( res );
                               },
                               function (){
                                  self.frozen( res );
                               },
                               function ( img ){
                                  self.created( res, img );
                               });
                         }
                       });
Software architecture
Model
Handel business logic and model relations, we add a wrapper on mongoose the ODM.

     module.exports = {
        virtuals : [ 'image' ],
        hooks : {
           pre : {
              save   : [ common.mark_new ],
              remove : [ common.backup_to( 'BakMockupImage' ), hooks.remove_from_mockup ]
           },
           post : {
              save   : [ hooks.add_to_mockup, common.add_to_auth( 'images' )],
              remove : [ hooks.remove_from_s3 ]
           }
        },
        statics : {
           insert : function ( args, next, forbidden, frozen, created ){ ... },
           index    : function ( args, next, no_content, forbidden, ok ){ .. },
           destroy : function ( args, next, no_content, forbidden, frozen, deleted ){ ... }
        },
        methods : {
           is_owner : function ( user_id ){ ... },
           created : function (){ ... },
           gen_url : function ( format ){ ... }
        }
     };
Software architecture
View
We use the fastest template engine thunder ( home brewed )



            <!DOCTYPE html>
            <html>
              <head>
                <meta charset="utf-8" />
                <title><?= it.title ?></title>
                <meta name="keywords" content="<?= it.keywords || '' ?>" />
                <meta name="description" content="<?= it.description || '' ?>" />
                <!--[if lt IE 9]>
                <meta http-equiv="refresh" content="0; url=/no-ie">
                <![endif]-->
                <?= it.css( it.styles ) ?>
              </head>
              <body>
                <? it.reset_asset_host(); ?>
                <?= it.body ?>
                <?= it.js( it.scripts ) ?>
              </body>
            </html>
Software architecture
Libraries
Extract reusable codes that is not relevant to model
Scaling node.js
Scaling node.js
Start small with built-in static server, node.js app & database all on the same server.
Scaling node.js
Use nginx as static server for better performance.
Scaling node.js
Use nginx as as proxy server as well to load balance requests.
The number of node.js app instance depends on how many CPU cores on the machine.
Scaling node.js
Split static files to different server for easier maintenance.
Scaling node.js
Use aws S3 for easier setup and maintenance.
Scaling node.js
Split database to another server. Make the node.js app server an unit.
Scaling node.js
Add a load balancer, add more app unit as the site scales up.
Scaling node.js
Add replica set if the database hits its limit.
Scaling node.js
Add CDN for static files for cross reign performance.
Scaling node.js
Split app to difference services as it scales up. Previous scaling steps apply to those services too.
Deployment
Deployment
With ssh, git; The server must stop during deployment.
Deployment
With ssh, git; 0 downtime deployment is possible since we have more than 1 instance( repo ).
Deployment
With ssh, git; Split static file makes it easier to deploy with multi instance( repo ) app.
Deployment
Deploying with multi machine it’s better to use image files on aws ec2.
THE END
 Thanks
QUESTIONS?

Contenu connexe

Tendances

An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications Rohan Chandane
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.jsdavidchubbs
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todaygerbille
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Jeado Ko
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
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
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법Jeado Ko
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigationBinary Studio
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJSRan Mizrahi
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenesBinary Studio
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS AnimationsEyal Vardi
 

Tendances (20)

An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Vue business first
Vue business firstVue business first
Vue business first
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
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)
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigation
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
 
Zend
ZendZend
Zend
 
Django
DjangoDjango
Django
 

En vedette

Xerox futures
Xerox futuresXerox futures
Xerox futuresheyzak
 
portfolio
portfolioportfolio
portfolioBen Lin
 
DeNA Sharing
DeNA SharingDeNA Sharing
DeNA SharingBen Lin
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.pptlExlthanachai
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 
4 T H I N G S Y O U C A N N O T R E C O V E R
4  T H I N G S  Y O U  C A N N O T  R E C O V E R4  T H I N G S  Y O U  C A N N O T  R E C O V E R
4 T H I N G S Y O U C A N N O T R E C O V E RShekhar Patil
 
POPAPP INVESTOR DECK
POPAPP INVESTOR DECKPOPAPP INVESTOR DECK
POPAPP INVESTOR DECKBen Lin
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.pptlExlthanachai
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.pptlExlthanachai
 
Company presentation
Company presentation Company presentation
Company presentation lifektisis
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
ElasticBeanstalk で新規事業を爆速ローンチする
ElasticBeanstalk で新規事業を爆速ローンチするElasticBeanstalk で新規事業を爆速ローンチする
ElasticBeanstalk で新規事業を爆速ローンチするRyo Shibayama
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architectureBen Lin
 
Amazon inspector で自動セキュリティ診断
Amazon inspector で自動セキュリティ診断Amazon inspector で自動セキュリティ診断
Amazon inspector で自動セキュリティ診断Ryo Shibayama
 

En vedette (16)

Xerox futures
Xerox futuresXerox futures
Xerox futures
 
portfolio
portfolioportfolio
portfolio
 
DeNA Sharing
DeNA SharingDeNA Sharing
DeNA Sharing
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.ppt
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
4 T H I N G S Y O U C A N N O T R E C O V E R
4  T H I N G S  Y O U  C A N N O T  R E C O V E R4  T H I N G S  Y O U  C A N N O T  R E C O V E R
4 T H I N G S Y O U C A N N O T R E C O V E R
 
POPAPP INVESTOR DECK
POPAPP INVESTOR DECKPOPAPP INVESTOR DECK
POPAPP INVESTOR DECK
 
product
productproduct
product
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.ppt
 
ฉันในอดีต2.ppt
ฉันในอดีต2.pptฉันในอดีต2.ppt
ฉันในอดีต2.ppt
 
Company presentation
Company presentation Company presentation
Company presentation
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
ElasticBeanstalk で新規事業を爆速ローンチする
ElasticBeanstalk で新規事業を爆速ローンチするElasticBeanstalk で新規事業を爆速ローンチする
ElasticBeanstalk で新規事業を爆速ローンチする
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architecture
 
Fear of failure
Fear of failureFear of failure
Fear of failure
 
Amazon inspector で自動セキュリティ診断
Amazon inspector で自動セキュリティ診断Amazon inspector で自動セキュリティ診断
Amazon inspector で自動セキュリティ診断
 

Similaire à Heroku pop-behind-the-sense

Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
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
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applicationsAstrails
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Fwdays
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architectureJasper Moelker
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRJavier Abadía
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.jsDavid Amend
 
reactjs-quiz..docs.pdf
reactjs-quiz..docs.pdfreactjs-quiz..docs.pdf
reactjs-quiz..docs.pdfAyanSarkar78
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoJavier Abadía
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebFabio Akita
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Codemotion
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Luciano Mammino
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 

Similaire à Heroku pop-behind-the-sense (20)

Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
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
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
reactjs-quiz..docs.pdf
reactjs-quiz..docs.pdfreactjs-quiz..docs.pdf
reactjs-quiz..docs.pdf
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações Web
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Vue js and Dyploma
Vue js and DyplomaVue js and Dyploma
Vue js and Dyploma
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 

Heroku pop-behind-the-sense

  • 2. About me Ben Lin Co-founder at WOOMOO INC. A full time entrepreneur & JavaScript lover Fall in love with node.js on Jun 2011 dreamerslab.com ben@dreamerslab.com twitter.com/dreamerslab github.com/dreamerslab
  • 3. About me COKE - Full stack node.js MVC framework Vodka - Functional testing framework Thunder - The lightning fast template engine And a lot more on https://github.com/dreamerslab
  • 4. Agenda 1. Software architecture 2. Frameworks & Libraries 3. Application stack 4. Packages 5. Scaling node.js 6. Deployment 7. Q & A
  • 6. Software architecture Home brewed node.js MVC framework - COKE Why node.js? It’s fast and easy to scale horizontally
  • 7. Software architecture Restful router for api & web server module.exports = function ( map ){ map.get( 'api', 'api/home#index' ); map.namespace( 'api', function ( api ){ api.resources( 'users', { only : [ 'create', 'show', 'update', 'destroy' ] }, function ( users ){ users.get( 'projects/:id/full', 'user_projects#full' ); users.resources( 'user_projects', { path : 'projects', only : [ 'create', 'index', 'show', 'update', 'destroy' ] }); // more routes ...... }); };
  • 8. Software architecture Validation make sure all the arguments are correct before get into controllers var form = require( 'express-form2' ); var field = form.field; var r = require( '../regex' ); module.exports = { validate_create : form( field( 'client_id' ).required().is( r.id, '01' ), field( 'mockup_id' ).required().is( r.id, '01' ), field( 'format' ).required().is( r.img, '014' ) ), validate_index : form( field( 'mockup_id' ).required().is( r.id, '01' ) ), validate_destroy : form( field( 'mockup_id' ).required().is( r.id, '01' ), field( 'id' ).required().is( r.id, '01' ) ) };
  • 9. Software architecture Controller Only do data exchange & flow control module.exports = Application.extend({ init : function ( before, after ){ before( this.is_authenticated ); before( this.validate_create ); before( this.has_file ); before( this.is_validate ); }, create : function ( req, res, next ){ var self = this; ProjectImage.insert( req.form, next, function (){ self.forbidden( res ); }, function (){ self.frozen( res ); }, function ( img ){ self.created( res, img ); }); } });
  • 10. Software architecture Model Handel business logic and model relations, we add a wrapper on mongoose the ODM. module.exports = { virtuals : [ 'image' ], hooks : { pre : { save : [ common.mark_new ], remove : [ common.backup_to( 'BakMockupImage' ), hooks.remove_from_mockup ] }, post : { save : [ hooks.add_to_mockup, common.add_to_auth( 'images' )], remove : [ hooks.remove_from_s3 ] } }, statics : { insert : function ( args, next, forbidden, frozen, created ){ ... }, index : function ( args, next, no_content, forbidden, ok ){ .. }, destroy : function ( args, next, no_content, forbidden, frozen, deleted ){ ... } }, methods : { is_owner : function ( user_id ){ ... }, created : function (){ ... }, gen_url : function ( format ){ ... } } };
  • 11. Software architecture View We use the fastest template engine thunder ( home brewed ) <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><?= it.title ?></title> <meta name="keywords" content="<?= it.keywords || '' ?>" /> <meta name="description" content="<?= it.description || '' ?>" /> <!--[if lt IE 9]> <meta http-equiv="refresh" content="0; url=/no-ie"> <![endif]--> <?= it.css( it.styles ) ?> </head> <body> <? it.reset_asset_host(); ?> <?= it.body ?> <?= it.js( it.scripts ) ?> </body> </html>
  • 12. Software architecture Libraries Extract reusable codes that is not relevant to model
  • 14. Scaling node.js Start small with built-in static server, node.js app & database all on the same server.
  • 15. Scaling node.js Use nginx as static server for better performance.
  • 16. Scaling node.js Use nginx as as proxy server as well to load balance requests. The number of node.js app instance depends on how many CPU cores on the machine.
  • 17. Scaling node.js Split static files to different server for easier maintenance.
  • 18. Scaling node.js Use aws S3 for easier setup and maintenance.
  • 19. Scaling node.js Split database to another server. Make the node.js app server an unit.
  • 20. Scaling node.js Add a load balancer, add more app unit as the site scales up.
  • 21. Scaling node.js Add replica set if the database hits its limit.
  • 22. Scaling node.js Add CDN for static files for cross reign performance.
  • 23. Scaling node.js Split app to difference services as it scales up. Previous scaling steps apply to those services too.
  • 25. Deployment With ssh, git; The server must stop during deployment.
  • 26. Deployment With ssh, git; 0 downtime deployment is possible since we have more than 1 instance( repo ).
  • 27. Deployment With ssh, git; Split static file makes it easier to deploy with multi instance( repo ) app.
  • 28. Deployment Deploying with multi machine it’s better to use image files on aws ec2.