SlideShare a Scribd company logo
1 of 62
How and why I roll my own
   node.js framework
Agenda

• A very brief introduction to node.js
• Personal technical skill background
• What is the minimal features a web framework must have?
• From express to plain node and back to express again
• Framework features
• Live demo
• Why do I roll my own node.js framework?
A very brief
introduction to
Node.js
What is node.js?
Node.js is a none-blocking
I/O , event-driven server-
side javascript. It runs on
google’s v8 javascript
engine.
Um ...
???
What is node really?
Node is JavaScript on the server
and it’s blazing fast
Personal technical skill background
Front-end developer ->
Node.js ->
Rails ->
Codeigniter(Php) ->
Rails(Ruby) ->
Node.js(JavaScript)
What is the minimal features
a web framework must have?
A.K.A
the most
important feature
Router?
NO
Code generators?
NO
ORM, Helpers,
Templates,
Command line
console ...
NO, NO, NO!!!
It’s project structure!
Example project structure


              .
              |-- configs.js
              |-- app
              | |-- controllers
              | |-- models
              | `-- views
              |-- core
              `-- public
                 |-- css
                 |-- img
                 `-- js
My first try
Define controllers


              // Ex. users.js
              module.exports = {

               index : function ( req, res ){
                 //...
               },

               show : function ( req, res ){
                 //...
               },

               new : function ( req, res ){
                 //...
               },

               create : function ( req, res ){
                 //...
               }

                // ....
              };
Load controllers into a hash



  var controllers = {};

  require( 'fs' ).readdir( PATH_TO_CONTROLLERS, function( err, files ){
   if( err ) throw err;

   files.forEach( function( file ){
    if( /.js$/.test( file )){
      var controller = require( PATH_TO_CONTROLLERS + file );

          Object.keys( controller ).forEach( function ( action ){
           var name = file.replace( '.js', '' );

            // Ex. controllers[ 'users/index' ] = controller[ action ];
            controllers[ name + '/' + action ] = controller[ action ];
          });
      }
    });
  });
Start server



        require( 'http' ).createServer( function( req, res ){
         var handler = require( 'url' ).
                   parse( req.url, true ).
                   pathname.
                   replace( /(/$)/g, '' );

          if( controllers[ handler ]){
            try{
              controllers[ handler ]( req, res );
            }catch( err ){
              res.error( 500, err );
            }
          }else{
            res.error( 404 );
          }
        }).listen( PORT, HOST );
From Express to plain node
and back to Express again
Intro to connect and express




        Node    -> Ruby
        Connect -> Rack
        Express -> Sinatra
What is middleware
and How does it work?
•WSGI (Python)
•Rack (Ruby)
•PSGI and Plack (Perl)
•Hack2 / WAI (Haskell)
•JSGI & Jack (JavaScript)
•Ring (Clojure)
•EWGI (Erlang)
•PHP Rack (PHP)
app.configure( function (){
  app.use( express.bodyParser());
  app.use( express.methodOverride());
  app.use( app.router );
});
Source: http://www.godfat.org/slide/2011-08-27-rest-
core.html#slide68
Middlewares, good or bad?
Performance <---> Flexibility
Flexibility and
maintainability
won the battle
Final features
• MVC structure.
• Mongoose as ODM (mongodb) with validation.
• Lightening fast template parsing with thunder.
• RESTful routing, supports namespace and nested resource.
• Middlewares and 3rd party libs support.
   ◦ All connect and express middlewares compatible.
   ◦ Socket.io compatible.
• Assets pipeline.
• Cluster support.
• Comprehensive logger for debugging.
• Command line tools.
   ◦ Powerful generators for project prototyping.
   ◦ Model command line console.
   ◦ Project routes inspecttion.
Packages that help to build
a web framework
Flow control
View parser
Asset packer
Inflection
Flow control
     var flow = new Flow();

     // set global variables
     flow.series( function ( next ){
       require( './lib/global' )( base_dir, next );
     }).

     // load logger
     series( function ( next ){
       require( CORE_DIR + 'logger' );
       // this has to go after the `require`
       LOG.sys( 'loading core module: logger' );
       next();
     }).

     // load util
     series( function ( next ){
       LOG.sys( 'loading core module: utils' );
       require( CORE_DIR + 'utils' );
       next();
     }).

     // load model
     series( function ( next ){
       LOG.sys( 'loading core module: model' );
       require( CORE_DIR + 'model' )( next );
     }).

     // load express
     series( function ( next ){
// load express
series( function ( next ){
  LOG.sys( 'loading core module: express' );
  require( CORE_DIR + 'express' )( next );
}).

// load lib
parallel( function ( results, ready ){
 var app = results[ 0 ];

  LOG.sys( 'loading core module: lib' );
  require( CORE_DIR + 'lib' )( app, ready );
}).

// load helper
parallel( function ( results, ready ){
 var app = results[ 0 ];

  LOG.sys( 'Loading helper: application' );
  require( HELPER_DIR + 'application' )( app );
  ready();
}).

// load assets
parallel( function ( results, ready ){
 var app = results[ 0 ];

  LOG.sys( 'loading core module: assets' );
  require( CORE_DIR + 'assets' )( app, ready );
}).

// overwrite res.send
parallel( function ( results, ready ){
 var app = results[ 0 ];

 LOG.sys( 'Overwriting express res.send' );
// overwrite res.send
         parallel( function ( results, ready ){
          var app = results[ 0 ];

           LOG.sys( 'Overwriting express res.send' );
           require( CORE_DIR + 'response' );
           ready();
         }).

         join().

         //load controller_brige
         series( function ( results, next ){
          var app = results[ 0 ][ 0 ];

           LOG.sys( 'loading core module: controller_bridge' );
           require( CORE_DIR + 'controller_bridge' )( app, next );
         }).

         // start server
         series( function ( app, next ){
           LOG.sys( 'loading core module: server' );
           require( CORE_DIR + 'server' )( app, next );
         }).

         // load 'after server start libs'
         end( function ( app ){
           LOG.sys( 'loading core module: started' );
           require( CORE_DIR + 'started' )( app );
         });




https://github.com/dreamerslab/node.flow
View parser

        <!DOCTYPE html>
        <html>
         <head>
          <title><?= it.title ?></title>
         </head>
         <body>
          <h1 class="header"><?= it.header ?></h1>
          <ul class="list">
          <? for( var i = 0, l = it.list.length; i < l; i++ ){ ?>
           <li class="item">'<?= it.list[ i ] ?>'</li>
          <? } ?>
          </ul>
         </body>
        </html>




https://github.com/dreamerslab/thunder
Asset packer
https://github.com/dreamerslab/node.packer




Inflection
https://github.com/dreamerslab/node.inflection
Yes,
most of the features
are from Rails
So why not just Rails?
Rails is quite slow
compare to node
Both
dev and production
env are hard to setup
***Dude I just want to write some code***
Backward compatibility is



       ‘0’
Don't get me wrong,
I still love its
architecture
and most of the
conventions
Best part of node
It’s a lot like
PHP in many ways
The language itself is
simple( but powerful )
You can start with
plain node and still
get your apps to work
very quickly
Depends on how complicated
your app is you can choose
different frameworks
builds on top of node
Live demo :D
Why I roll my own node.js
framework?
It’s fun !
You will definitely learn a lot in the process even if your framework is
not as popular as rails you should still give it a try. It really helps you
understanding how a framework work so that you can write better app
code.
Happy coding :)
Ben Lin
 ben@dreamerslab.com
 http://twitter.com/dreamerslab
 https://github.com/dreamerslab

More Related Content

What's hot

Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAnkit Agarwal
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaFlorent Pillet
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudHiro Asari
 
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
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyyamanekko
 
The road to Ember.js 2.0
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0Codemotion
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportBen Scofield
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node jsThomas Roch
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev ConfTom Croucher
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mochaRevath S Kumar
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverMongoDB
 

What's hot (20)

Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Ruby meets Go
Ruby meets GoRuby meets Go
Ruby meets Go
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
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
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mruby
 
The road to Ember.js 2.0
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
OneRing @ OSCamp 2010
OneRing @ OSCamp 2010OneRing @ OSCamp 2010
OneRing @ OSCamp 2010
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 

Similar to How and why i roll my own node.js framework

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
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
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeDanielle Madeley
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-senseBen Lin
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascriptaglemann
 
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.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascriptEldar Djafarov
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first classFin Chen
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 

Similar to How and why i roll my own node.js framework (20)

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
NodeJS
NodeJSNodeJS
NodeJS
 
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
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
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.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first class
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 

More from Ben Lin

portfolio
portfolioportfolio
portfolioBen Lin
 
DeNA Sharing
DeNA SharingDeNA Sharing
DeNA SharingBen Lin
 
POPAPP INVESTOR DECK
POPAPP INVESTOR DECKPOPAPP INVESTOR DECK
POPAPP INVESTOR DECKBen Lin
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architectureBen Lin
 
Node.js basics
Node.js basicsNode.js basics
Node.js basicsBen Lin
 

More from Ben Lin (6)

portfolio
portfolioportfolio
portfolio
 
product
productproduct
product
 
DeNA Sharing
DeNA SharingDeNA Sharing
DeNA Sharing
 
POPAPP INVESTOR DECK
POPAPP INVESTOR DECKPOPAPP INVESTOR DECK
POPAPP INVESTOR DECK
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architecture
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 

Recently uploaded

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Recently uploaded (20)

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

How and why i roll my own node.js framework

  • 1. How and why I roll my own node.js framework
  • 2. Agenda • A very brief introduction to node.js • Personal technical skill background • What is the minimal features a web framework must have? • From express to plain node and back to express again • Framework features • Live demo • Why do I roll my own node.js framework?
  • 5. Node.js is a none-blocking I/O , event-driven server- side javascript. It runs on google’s v8 javascript engine.
  • 7. ???
  • 8. What is node really?
  • 9. Node is JavaScript on the server
  • 12. Front-end developer -> Node.js -> Rails -> Codeigniter(Php) -> Rails(Ruby) -> Node.js(JavaScript)
  • 13. What is the minimal features a web framework must have?
  • 16. NO
  • 18. NO
  • 22. Example project structure . |-- configs.js |-- app | |-- controllers | |-- models | `-- views |-- core `-- public |-- css |-- img `-- js
  • 24. Define controllers // Ex. users.js module.exports = { index : function ( req, res ){ //... }, show : function ( req, res ){ //... }, new : function ( req, res ){ //... }, create : function ( req, res ){ //... } // .... };
  • 25. Load controllers into a hash var controllers = {}; require( 'fs' ).readdir( PATH_TO_CONTROLLERS, function( err, files ){ if( err ) throw err; files.forEach( function( file ){ if( /.js$/.test( file )){ var controller = require( PATH_TO_CONTROLLERS + file ); Object.keys( controller ).forEach( function ( action ){ var name = file.replace( '.js', '' ); // Ex. controllers[ 'users/index' ] = controller[ action ]; controllers[ name + '/' + action ] = controller[ action ]; }); } }); });
  • 26. Start server require( 'http' ).createServer( function( req, res ){ var handler = require( 'url' ). parse( req.url, true ). pathname. replace( /(/$)/g, '' ); if( controllers[ handler ]){ try{ controllers[ handler ]( req, res ); }catch( err ){ res.error( 500, err ); } }else{ res.error( 404 ); } }).listen( PORT, HOST );
  • 27. From Express to plain node and back to Express again
  • 28. Intro to connect and express Node -> Ruby Connect -> Rack Express -> Sinatra
  • 29. What is middleware and How does it work?
  • 30. •WSGI (Python) •Rack (Ruby) •PSGI and Plack (Perl) •Hack2 / WAI (Haskell) •JSGI & Jack (JavaScript) •Ring (Clojure) •EWGI (Erlang) •PHP Rack (PHP)
  • 31. app.configure( function (){ app.use( express.bodyParser()); app.use( express.methodOverride()); app.use( app.router ); });
  • 37. • MVC structure. • Mongoose as ODM (mongodb) with validation. • Lightening fast template parsing with thunder. • RESTful routing, supports namespace and nested resource. • Middlewares and 3rd party libs support. ◦ All connect and express middlewares compatible. ◦ Socket.io compatible. • Assets pipeline. • Cluster support. • Comprehensive logger for debugging. • Command line tools. ◦ Powerful generators for project prototyping. ◦ Model command line console. ◦ Project routes inspecttion.
  • 38. Packages that help to build a web framework
  • 39. Flow control View parser Asset packer Inflection
  • 40. Flow control var flow = new Flow(); // set global variables flow.series( function ( next ){ require( './lib/global' )( base_dir, next ); }). // load logger series( function ( next ){ require( CORE_DIR + 'logger' ); // this has to go after the `require` LOG.sys( 'loading core module: logger' ); next(); }). // load util series( function ( next ){ LOG.sys( 'loading core module: utils' ); require( CORE_DIR + 'utils' ); next(); }). // load model series( function ( next ){ LOG.sys( 'loading core module: model' ); require( CORE_DIR + 'model' )( next ); }). // load express series( function ( next ){
  • 41. // load express series( function ( next ){ LOG.sys( 'loading core module: express' ); require( CORE_DIR + 'express' )( next ); }). // load lib parallel( function ( results, ready ){ var app = results[ 0 ]; LOG.sys( 'loading core module: lib' ); require( CORE_DIR + 'lib' )( app, ready ); }). // load helper parallel( function ( results, ready ){ var app = results[ 0 ]; LOG.sys( 'Loading helper: application' ); require( HELPER_DIR + 'application' )( app ); ready(); }). // load assets parallel( function ( results, ready ){ var app = results[ 0 ]; LOG.sys( 'loading core module: assets' ); require( CORE_DIR + 'assets' )( app, ready ); }). // overwrite res.send parallel( function ( results, ready ){ var app = results[ 0 ]; LOG.sys( 'Overwriting express res.send' );
  • 42. // overwrite res.send parallel( function ( results, ready ){ var app = results[ 0 ]; LOG.sys( 'Overwriting express res.send' ); require( CORE_DIR + 'response' ); ready(); }). join(). //load controller_brige series( function ( results, next ){ var app = results[ 0 ][ 0 ]; LOG.sys( 'loading core module: controller_bridge' ); require( CORE_DIR + 'controller_bridge' )( app, next ); }). // start server series( function ( app, next ){ LOG.sys( 'loading core module: server' ); require( CORE_DIR + 'server' )( app, next ); }). // load 'after server start libs' end( function ( app ){ LOG.sys( 'loading core module: started' ); require( CORE_DIR + 'started' )( app ); }); https://github.com/dreamerslab/node.flow
  • 43. View parser <!DOCTYPE html> <html> <head> <title><?= it.title ?></title> </head> <body> <h1 class="header"><?= it.header ?></h1> <ul class="list"> <? for( var i = 0, l = it.list.length; i < l; i++ ){ ?> <li class="item">'<?= it.list[ i ] ?>'</li> <? } ?> </ul> </body> </html> https://github.com/dreamerslab/thunder
  • 45. Yes, most of the features are from Rails
  • 46. So why not just Rails?
  • 47. Rails is quite slow compare to node
  • 48. Both dev and production env are hard to setup
  • 49. ***Dude I just want to write some code***
  • 51. Don't get me wrong, I still love its architecture and most of the conventions
  • 52. Best part of node
  • 53. It’s a lot like PHP in many ways
  • 54. The language itself is simple( but powerful )
  • 55. You can start with plain node and still get your apps to work very quickly
  • 56. Depends on how complicated your app is you can choose different frameworks builds on top of node
  • 58. Why I roll my own node.js framework?
  • 60. You will definitely learn a lot in the process even if your framework is not as popular as rails you should still give it a try. It really helps you understanding how a framework work so that you can write better app code.
  • 62. Ben Lin ben@dreamerslab.com http://twitter.com/dreamerslab https://github.com/dreamerslab

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n