Server Side Apocalypse, JS
About Me
Md. Sohel Rana
Founder, NerdDevs
http://www.nerddevs.com
twitter : @sohel023010
skype : sohel023010
http://blog.sohel.me
Client
  Browser
  A Desktop App
  Rest Client
  Server? Yes!
Server
  Serves data, images, files, audio, video etc.
  Sometimes foods as well! Foodpanda J
Server Side Scripting
  ASP, ASP.NET, Java, PHP, Haskell, Perl, Python, Ruby
and so on!
  And also JavaScript
  JavaScript brought non-blocking IO
  It changed the way how server works
  We got NodeJS
NodeJS
  A runtime environment
to support JavaScript as
server side language
  Built on V8-JavaScript
Engine of Chrome, Fast
  Event-driven, non-
blocking I/O
NodeJS
  Advantages over others
- Asynchronous I/O, more request can server
- JavaScript as a Server Side language
- Event Driven
- Callbacks
- A good package manager “NPM”
  Disadvantages
- Single threaded
- Lack of standard libraries
NodeJS
An http server :
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(9000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:9000/');
Node Modules
  A functional unit that
performs specified actions
  Loaded using
require(‘module_name’)
  Usually placed at
node_modules folder
  Non-native modules
loaded searching upwards
Node Modules
A simple module :
// “modules/calculator.js”
exports.add = function(a, b){
return a+b ;
};
exports.subtract = function(a, b){
return a-b;
};
var Calculator = require('./module/calculator.js');
var addTwoNumber = Calculator.add(5,7);
NPM
  NPM- nodejs package
manager
  Used for install/
uninstall node
programs
  Can be used to install
dependencies
package.json is used to
define dependencies
//pakage.json
{
"name": "backbone-express-boilerplate",
"version": "1.0.0",
"scripts": {
"start": "node ./server/bin/www"
},
"dependencies": {
"express": "^4.12.3",
"body-parser": "~1.12.0",
"cookie-parser": "~1.3.4",
"jade": "~1.9.2",
"serve-favicon": "~2.2.0"
},
"repository": {
"type": "git",
"url": "https://github.com/sohel-rana/backbone-
express-boilerplate.git"
},
"author": "Sohel Rana”,
"bugs": {
"url": "https://github.com/sohel-rana/backbone-
express-boilerplate/issues"
},
"homepage": "https://github.com/sohel-rana/
backbone-express-boilerplate"
}
Web Frameworks
NodeJS provides core
modules
  Requires lots of effort for
web apps
  Express, Sails etc. provides
lots of feature top of it
  Makes the project
manageable
Case Studies
  LinkedIn moved from Rails to Node, reduced their
server uses from 30 to 3
  Microsoft, Walmart, eBay, Paypal all uses nodejs for
some of their services
  And there are many more here
Throw all?
  Throw all other and use
NodeJS? NO!
NodeJS is good to handle
many request.
  But will not perform well
when we need more CPU
  Suitable for real-time
applications
  Chat, online games ,
collaboration tools etc.

Server Side Apocalypse, JS

  • 1.
  • 2.
    About Me Md. SohelRana Founder, NerdDevs http://www.nerddevs.com twitter : @sohel023010 skype : sohel023010 http://blog.sohel.me
  • 3.
    Client   Browser   ADesktop App   Rest Client   Server? Yes!
  • 4.
    Server   Serves data,images, files, audio, video etc.   Sometimes foods as well! Foodpanda J
  • 5.
    Server Side Scripting  ASP, ASP.NET, Java, PHP, Haskell, Perl, Python, Ruby and so on!   And also JavaScript   JavaScript brought non-blocking IO   It changed the way how server works   We got NodeJS
  • 6.
    NodeJS   A runtimeenvironment to support JavaScript as server side language   Built on V8-JavaScript Engine of Chrome, Fast   Event-driven, non- blocking I/O
  • 7.
    NodeJS   Advantages overothers - Asynchronous I/O, more request can server - JavaScript as a Server Side language - Event Driven - Callbacks - A good package manager “NPM”   Disadvantages - Single threaded - Lack of standard libraries
  • 8.
    NodeJS An http server: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(9000, '127.0.0.1'); console.log('Server running at http://127.0.0.1:9000/');
  • 9.
    Node Modules   Afunctional unit that performs specified actions   Loaded using require(‘module_name’)   Usually placed at node_modules folder   Non-native modules loaded searching upwards
  • 10.
    Node Modules A simplemodule : // “modules/calculator.js” exports.add = function(a, b){ return a+b ; }; exports.subtract = function(a, b){ return a-b; }; var Calculator = require('./module/calculator.js'); var addTwoNumber = Calculator.add(5,7);
  • 11.
    NPM   NPM- nodejspackage manager   Used for install/ uninstall node programs   Can be used to install dependencies package.json is used to define dependencies //pakage.json { "name": "backbone-express-boilerplate", "version": "1.0.0", "scripts": { "start": "node ./server/bin/www" }, "dependencies": { "express": "^4.12.3", "body-parser": "~1.12.0", "cookie-parser": "~1.3.4", "jade": "~1.9.2", "serve-favicon": "~2.2.0" }, "repository": { "type": "git", "url": "https://github.com/sohel-rana/backbone- express-boilerplate.git" }, "author": "Sohel Rana”, "bugs": { "url": "https://github.com/sohel-rana/backbone- express-boilerplate/issues" }, "homepage": "https://github.com/sohel-rana/ backbone-express-boilerplate" }
  • 12.
    Web Frameworks NodeJS providescore modules   Requires lots of effort for web apps   Express, Sails etc. provides lots of feature top of it   Makes the project manageable
  • 13.
    Case Studies   LinkedInmoved from Rails to Node, reduced their server uses from 30 to 3   Microsoft, Walmart, eBay, Paypal all uses nodejs for some of their services   And there are many more here
  • 14.
    Throw all?   Throwall other and use NodeJS? NO! NodeJS is good to handle many request.   But will not perform well when we need more CPU   Suitable for real-time applications   Chat, online games , collaboration tools etc.