NodeWay in my project & sails.js

Post on 06-May-2015

4,666 views 0 download

Tags:

transcript

NodeWay

dovchar 2013

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

✦ Main language: Javascript

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

✦ Main language: Javascript

✦ Hobby language: Go

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

✦ Main language: Javascript

✦ Hobby language: Go

✦ Pacemaker conference

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

✦ Main language: Javascript

✦ Hobby language: Go

✦ Pacemaker conference

✦ Script’n’Code meet-up

dovchar itweekend 2013

Abo

ut m

e

✦ 7 years in IT

✦ 3 years in SoftServe

✦ 7 months Application Architect

✦ Main language: Javascript

✦ Hobby language: Go

✦ Pacemaker conference

✦ Script’n’Code meet-up

✦ Open source (typescript grails, clio go, sonar qunit)

dovchar itweekend 2013

Abo

ut m

e

dovchar itweekend 2013

Age

nda

NodeWay in my project

dovchar itweekend 2013

Age

nda

NodeWay in my project NodeWay in my dreams

dovchar itweekend 2013

Age

nda

NodeWay in my project NodeWay in my dreams

✦Nodejs✦Installation ✦My Project✦Architecture✦Project statistics ✦Code health goal✦Before✦After✦Development process ✦Conclusion

dovchar itweekend 2013

Age

nda

NodeWay in my project NodeWay in my dreams

✦Nodejs✦Installation ✦My Project✦Architecture✦Project statistics ✦Code health goal✦Before✦After✦Development process ✦Conclusion

dovchar itweekend 2013

✦What is Sails✦Features ✦Get Started✦MVC Structure✦Routers ✦Assets✦Policies✦Deployment✦Sockets ✦Conclusion

Age

nda

Nod

eJS

dovchar itweekend 2013

«Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works.»

Wikipedia

Nod

eJS

dovchar itweekend 2013

«Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works.»

Wikipedia

‣Original author(s): Ryan Lienhart Dahl‣Stable release: 0.10.18 / September 4, 2013‣Preview release: 0.11.7 / August 21, 2013‣Development status: Active‣Written in C++, JavaScript‣Operating system: Mac OS X, Linux, Solaris, FreeBSD, OpenBSD, Windows (older versions require Cygwin), webOS‣Type: Event-driven networking‣License: MIT‣Website: nodejs.org

Nod

eJS

dovchar itweekend 2013

«Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works.»

Wikipedia

‣Original author(s): Ryan Lienhart Dahl‣Stable release: 0.10.18 / September 4, 2013‣Preview release: 0.11.7 / August 21, 2013‣Development status: Active‣Written in C++, JavaScript‣Operating system: Mac OS X, Linux, Solaris, FreeBSD, OpenBSD, Windows (older versions require Cygwin), webOS‣Type: Event-driven networking‣License: MIT‣Website: nodejs.org

Inst

alla

tion

dovchar itweekend 2013

Install on OSXUsing a package:Simply download Macintosh Installer

Using homebrew:brew install nodeUsing macports:port install nodejs

Inst

alla

tion

dovchar itweekend 2013

Install on LinuxUbuntu, MintExample install:sudo apt-get install python-software-properties python g++ makesudo add-apt-repository ppa:chris-lea/node.jssudo apt-get updatesudo apt-get install nodejsIt installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-commonpackage for the add-apt-repository command to work: sudo apt-get install software-properties-commonAs of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed fromnode to nodejs. You'll need to

symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

Inst

alla

tion

dovchar itweekend 2013

Install on WindowsUsing a package:Simply download Windows Installer.

Using chocolatey to install Node:cinst nodejs or for full install with NPM:cinst nodejs.install

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Abo

ut P

roje

ct

dovchar itweekend 2013

Arc

hite

ctur

e

dovchar itweekend 2013

Arc

hite

ctur

e

dovchar itweekend 2013

Arc

hite

ctur

e

dovchar itweekend 2013

Proj

ect S

tatis

tics

dovchar itweekend 2013

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

✦ 3200 javascript files

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

✦ 3200 javascript files

✦ 200.000 lines of code

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

✦ 3200 javascript files

✦ 200.000 lines of code

✦ 1.826 total violations

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

✦ 3200 javascript files

✦ 200.000 lines of code

✦ 1.826 total violations

✦ 28.3% average coverage

Proj

ect S

tatis

tics

dovchar itweekend 2013

✦ 2 years development

✦ 10 scrum teams

✦ 59 modules

✦ 3200 javascript files

✦ 200.000 lines of code

✦ 1.826 total violations

✦ 28.3% average coverage

✦ >5000 unit tests

What is Node.js doing here?!

dovchar itweekend 2013

Code health goal 90%

dovchar itweekend 2013

Cod

e H

ealth

dovchar itweekend 2013

Source

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Duplications

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Duplications

Unit tests

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Duplications

Unit tests

Complexity

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Duplications

Unit tests

Potential bugs Complexity

Cod

e H

ealth

dovchar itweekend 2013

Source

Architecture &Design

Duplications

Coding rules Unit tests

Potential bugs Complexity

Cod

e H

ealth

dovchar itweekend 2013

Source

Comments

Architecture &Design

Duplications

Coding rules Unit tests

Potential bugs Complexity

Befo

re

dovchar itweekend 2013

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

✦ JSTD: js test driver for running tests on CI

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

✦ JSTD: js test driver for running tests on CI

✦ Strange custom ruby scripts (still have no idea what they were used for :)

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

✦ JSTD: js test driver for running tests on CI

✦ Strange custom ruby scripts (still have no idea what they were used for :)

✦ Sonar showed only back-end code

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

✦ JSTD: js test driver for running tests on CI

✦ Strange custom ruby scripts (still have no idea what they were used for :)

✦ Sonar showed only back-end code

✦ Code coverage was to get in a separate application which made the automatic analysis even more complicated

Befo

re

dovchar itweekend 2013

✦ A lot of manual work

✦ More than 5 different sources for analysis and counting

✦ JSTD: js test driver for running tests on CI

✦ Strange custom ruby scripts (still have no idea what they were used for :)

✦ Sonar showed only back-end code

✦ Code coverage was to get in a separate application which made the automatic analysis even more complicated

✦ Code health was counted in exel with its magic formulas that mysteriously worked hiding the real problems

Total CRAP...

dovchar itweekend 2013

Afte

r

dovchar itweekend 2013

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

✦ We’ve chosen grunt.js for running node.js tasks (running unit tests, counting code coverage, creating reports for Sonar, checking the code semantics and complexity: jshint)

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

✦ We’ve chosen grunt.js for running node.js tasks (running unit tests, counting code coverage, creating reports for Sonar, checking the code semantics and complexity: jshint)

✦ We’ve excluded any manual intervention: sided applications for code coverage, exel creepy files, etc.

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

✦ We’ve chosen grunt.js for running node.js tasks (running unit tests, counting code coverage, creating reports for Sonar, checking the code semantics and complexity: jshint)

✦ We’ve excluded any manual intervention: sided applications for code coverage, exel creepy files, etc.

✦ We’ve put counting code health on Sonar’s shoulders for back-end as well as UI

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

✦ We’ve chosen grunt.js for running node.js tasks (running unit tests, counting code coverage, creating reports for Sonar, checking the code semantics and complexity: jshint)

✦ We’ve excluded any manual intervention: sided applications for code coverage, exel creepy files, etc.

✦ We’ve put counting code health on Sonar’s shoulders for back-end as well as UI

✦ We’ve fastened unit testing on CI

Afte

r

dovchar itweekend 2013

✦ We’ve refused from everything we had before but the existing tests

✦ We’ve decided to switch to node.js for non-functional requirements

✦ We’ve chosen grunt.js for running node.js tasks (running unit tests, counting code coverage, creating reports for Sonar, checking the code semantics and complexity: jshint)

✦ We’ve excluded any manual intervention: sided applications for code coverage, exel creepy files, etc.

✦ We’ve put counting code health on Sonar’s shoulders for back-end as well as UI

✦ We’ve fastened unit testing on CI

✦ We’ve prevented the developers from failed builds and have given them the clear system for code quality analysis and correction

Exam

ple

dovchar itweekend 2013

Dev

elop

men

t pro

cess

dovchar itweekend 2013

Con

clus

ion

dovchar itweekend 2013

Con

clus

ion

dovchar itweekend 2013

Con

clus

ion

dovchar itweekend 2013

+

Con

clus

ion

dovchar itweekend 2013

+

Con

clus

ion

dovchar itweekend 2013

+ +

Con

clus

ion

dovchar itweekend 2013

+ +

Con

clus

ion

dovchar itweekend 2013

=

+ +

Con

clus

ion

dovchar itweekend 2013

=

+ +

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Nod

ejs f

ram

ewor

ks

dovchar itweekend 2013

Sails

dovchar itweekend 2013

What is Sails.js?

Sails

dovchar itweekend 2013

Sails.js make it easy to build custom, enterprise-grade Node.js apps. It is designed to mimic the MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with scalable, service-oriented architecture. It's especially good for building chat, realtime dashboards, or multiplayer games.

What is Sails.js?

Feat

ures

dovchar itweekend 2013

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

✦ Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

✦ Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.

✦ Realtime Socket.io requests are routed to your controllers the same way as everything else: with resourceful conventions and URL mappings.

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

✦ Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.

✦ Realtime Socket.io requests are routed to your controllers the same way as everything else: with resourceful conventions and URL mappings.

✦ Sails.js provides basic security and role-based access control by default, and you can add as many custom policies as you like.

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

✦ Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.

✦ Realtime Socket.io requests are routed to your controllers the same way as everything else: with resourceful conventions and URL mappings.

✦ Sails.js provides basic security and role-based access control by default, and you can add as many custom policies as you like.

✦ Because Express and Socket.io share the same configurable session store, all of your security policies are reused for realtime WebSocket requests as well.

Feat

ures

dovchar itweekend 2013

✦ Sails.js is database agnostic. Its ORM, Waterline, provides a simple data access layer that works, no matter what database you're using.

✦ Sails.js automatically generates a RESTful JSON API for your app. That means you don't have to write any backend code to build simple database apps.

✦ Realtime Socket.io requests are routed to your controllers the same way as everything else: with resourceful conventions and URL mappings.

✦ Sails.js provides basic security and role-based access control by default, and you can add as many custom policies as you like.

✦ Because Express and Socket.io share the same configurable session store, all of your security policies are reused for realtime WebSocket requests as well.

✦ Sails.js has automatic asset minification. With Sails, you just put your files in the proper folder and they are automatically included in your layout. Then, when you're ready to go into production, they are minified and gzipped to preserve as much bandwidth as possible.

Get

Sta

rted

dovchar itweekend 2013

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Get

Sta

rted

dovchar itweekend 2013

npm install -g sails

Con

trolle

r

dovchar itweekend 2013

Con

trolle

r

dovchar itweekend 2013

Con

trolle

r

dovchar itweekend 2013

Con

trolle

r

dovchar itweekend 2013

Con

trolle

r

dovchar itweekend 2013

Con

trolle

r

dovchar itweekend 2013

✦ req.param()

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson✦ res.view()

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson✦ res.view()✦ res.send()

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson✦ res.view()✦ res.send()✦ res.json()

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson✦ res.view()✦ res.send()✦ res.json()✦ res.redirect()

Con

trolle

r

dovchar itweekend 2013

✦ req.param()✦ req.isSocket✦ req.isAjax✦ req.isJson✦ res.view()✦ res.send()✦ res.json()✦ res.redirect()✦ res.viewExists

Mod

el

dovchar itweekend 2013

Mod

el

dovchar itweekend 2013

Mod

el

dovchar itweekend 2013

Mod

el

dovchar itweekend 2013

Mod

el

dovchar itweekend 2013

✦ Attributes

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

✦ Adapters

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

✦ Adapters

✦ Associations

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

✦ Adapters

✦ Associations

✦ Automatic schema creation

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

✦ Adapters

✦ Associations

✦ Automatic schema creation

✦ Data manipulation: create, findOne, find, dynamic finders (i.e findByName), update, destroy,

Mod

el

dovchar itweekend 2013

✦ Attributes

✦ Validations

✦ Instance Methods (save, destroy, toObject, toJSON)

✦ Custom Defined Instance Methods

✦ Lifecycle callbacks

✦ Custom tables name

✦ Adapters

✦ Associations

✦ Automatic schema creation

✦ Data manipulation: create, findOne, find, dynamic finders (i.e findByName), update, destroy,

✦ Migrations

dovchar itweekend 2013

View

/Ass

ets

Rout

ers

dovchar itweekend 2013

Rout

ers

dovchar itweekend 2013

✦ If the URL is not specified in config/routes.js, the default route for a URL is: /:controller/:action/:id where :controller, :action, and the :id request parameter are derived from the url.

✦ If the requested controller/action doesn't exist: - if a view exists ( /views/:controller/:action.ejs), Sails will render that view - if no view exists, but a model exists, Sails will automatically generate a JSON API for the model which matches :controller. - if no view OR model exists, Sails will respond with a 404.

Rout

ers

dovchar itweekend 2013

✦ If the URL is not specified in config/routes.js, the default route for a URL is: /:controller/:action/:id where :controller, :action, and the :id request parameter are derived from the url.

✦ If the requested controller/action doesn't exist: - if a view exists ( /views/:controller/:action.ejs), Sails will render that view - if no view exists, but a model exists, Sails will automatically generate a JSON API for the model which matches :controller. - if no view OR model exists, Sails will respond with a 404.

Und

er th

e hu

d

dovchar itweekend 2013

Und

er th

e hu

d

dovchar itweekend 2013

✦ Policies

✦ Custom adapters

✦ Deployment

✦ Configurations

✦ Database support

✦ Sockets

Con

clus

ion

dovchar itweekend 2013

Link

s

dovchar itweekend 2013

Link

s

dovchar itweekend 2013

✦ Node.js

Link

s

dovchar itweekend 2013

✦ Node.js

✦ Sonarqube

Que

stio

ns?

dovchar itweekend 2013

Questions?

dovchar itweekend 2013