Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
NodeJS
JsFoo!
Wifi Details
• SSID:
• HasGeek
• HasGeek-Wifi
• Password:
• geeksrus
About me
• Currently Head of Engineering @
Hopscotch
• Xoogler
• Entrepreneur
• Corporate Trainer
• Author
• AngularJS & A...
Agenda
• 1 day
• Smaller, multiple sessions
• Code Along
• As fast or slow as needed
• Questions, interrupt any time
Agenda - Continued
• Introduction
• JS on the Server
• NodeJS Concepts
• Starting NodeJS
• NPM & Requires
Agenda - Continued
• Working with Node
packages
• Async
• Express
• Routes & Config
• NPM & Requires
Agenda - Continued
• Middleware
• Working with MongoDB
• Build & Deploy
• Sockets?
Requirements
• NodeJS (http://nodejs.org)
• A good IDE (Recommend Webstorm)
Getting the Code Base
http://is.gd/nodejsfoo
The Basics
Agenda
• Introduction
• JS On the Server & Evolution
• NodeJS - How it works
• Basic Concepts and Terminologies
• Hello No...
Evolution of Server side
programming
• CGI / Perl
• Java / ASP
• Ruby, PHP, Python
• Move towards reusable, maintainable, ...
Why JS on the server side
sounds crazy!
Single Threaded Slow, Clunky
No OO! No Type Safety
What changed?
libev V8
• Event Engine
• Non blocking
• Core underlying
NodeJS
• JS Engine
• From Chromium
• Super Fast!
So what is NodeJS?
Not a programming language, but not simply
a framework either. For servers as well as for
scripts!
Core NodeJS Concepts
Event Loop! Non blocking
Single
Threaded
Callbacks
FTW!
A Thinking Paradigm Shift
teams = teamsDb.getTeams();
for (var i = 0; i < teams.size(); i++) {
team = teams.get(i);
team.s...
How would we speed it up?
• Threading?
• Parallelization?
• Identifying the bottlenecks
What if?
• teamDb.getTeams was asynchronous
• teamDb.getTeams(function(teams) {});
• Same for teamDb.getTeamExtraInfo
• te...
A Thinking Paradigm Shift
teamsDb.getTeams(function(teams) {
for (var i = 0; i < teams.size(); i++) {
team = teams.get(i);...
Now what about NodeJS?
• Callback oriented
• Forced to think about what to do about
callback
• Forces you to think if you ...
Installing Node
• Directly, from nodejs.org
• Using nvm – Node Version Manager
– Easier to update, and switch versions
When to use NodeJS?
• IO intensive
– File, DB
• Web Servers
– More concurrent connections, cheaper!
• Scripts / Tools
– Co...
When to avoid NodeJS
• CPU intensive
• Long running synchronous tasks
• Mathematical Operations – Floating
Numbers
So how do we start?
• Hello world example
Code-along starts now
Github Repo
http://is.gd/nodejsfoo
Code Along – Initial Setup
Checkout:
git clone https://github.com/Fundoo-
Solutions/nodejsfoo.git
cd nodejsfoo
Code Along
Step 1 - Simple Hello World
Step 2 - Handling Arguments & Inputs
Step 3 - Using Inbuilt Libraries
Step 4 - Even...
Step 1 – Simple Hello World
• console.log
• With multiple arguments
• Running it
• node <filename>
Step 2 - Handling Arguments and
Inputs
• process.argv
• First two arguments
• node
• filename
• Then
• arguments in order ...
Step 3 – Inbuilt Libraries - fs
• Pull in libraries using
• require()
• require(‘fs’);
• fs.readFileSync(filename, encodin...
Step 4 – Event handling and
callbacks
• var stream = fs.createReadStream(filename)
• stream.on(‘data’, function(data) {})
...
Step 5 – Sharing logic
between files
• module.exports = {getStocks:}
• require
• Starting with ./ for relative!
• fs.readF...
Core Inbuilt Libraries
• fs
• http
• url
What about?
• Sockets
• Web Servers
• Configuration
• Database / ORM
• Something else?
Introducing NPM
• Node Package Manager
• Equivalent to Maven in Java
• Comprises
• package.json
• Global + local packages
How many NPM Packages are out
there?
1,80,000+
How does a package.json
look like?
{
"name": ”DEMO App",
"description": "DEMO App for Workshop",
"version": "0.0.1",
"priv...
Installing a package
npm install package-name
Installing a global package
npm install –g package-name
Installing all packages for a
project
npm install
(assuming a package.json file)
Installing a package & saving it to
package.json
npm install --save package-name
Start to server
Agenda
• Working with Node packages
• NPM & Requires
• Async
• Express
• Routes & Config
How does a package.json
look like?
{
"name": ”DEMO App",
"description": "DEMO App for Workshop",
"version": "0.0.1",
"priv...
Package.json syntax &
versioning
• MAJOR.MINOR.PATCH
• “primus”: “1.2.3”
• Specific
• *, x - wildcard support
• “async”: “...
Package.json syntax &
versioning
• ^ - More relaxed versioning
• “async” : “^0.8.0”
• >= 0.8.0
• < 1.0.0
• Recommendation:...
Package.json – Dependencies vs
Dev Dependencies
• dependencies
• Always needed
• Production!
• devDependencies
• Same synt...
npm Scripts
• scripts: {}
• test, start, whateveryouwant
• Shell commands
• echo “Deploying…”
• node index.js
• Shortcuts
...
async
• For easier dealing with multiple asynchronous
calls
• Point in case, async.parallel
• An array or object with func...
Code Along
Step 6 - Init your package.son
Step 7 - Install and use async
Step 6 - Initing Package.son
npm init
(And answer all the questions)
Step 7 – Use async
• npm install --save async
• Understanding async parallel
• read files in async.parallel
• Do composite...
Express
• A web server framework for NodeJS
• The de-facto web server for most NodeJS apps
• The E in MEAN stack
• Configu...
Express Components
Routing Handlers
Middlewares
Templating /
Rendering
Creating an Express NodeJS
App
If from scratch
(npm install –g express)
express init
AngularJS + Express?
Use the angular-fullstack Yeoman generator
Express Router
• app.
• get
• post
• put
• delete
• patch
• and more…
Express Handlers
• function(req, res) {}
• function(req, res, next) {}
• What’s next?
• function(err, req, res, next) {}
Code Along
Step 8 - Start an express app
Step 9 - Create routes and handlers
Step 10 - Handling post requests
Step 8 – Start Express App
• npm install --save express
• var express = require(‘express’);
• var app = express();
• app.l...
Step 9 – Create routes and
handlers
• Move logic into get(‘/)
• res.send(json);
• or res.json(json);
• Parametrized get (‘...
Step 10 – Handling post
routes
• npm install --save body-parser
• app.use(bodyParser.urlencoded({extended: true}));
• app....
Express Configuration
• Environment based
• Global + Environment Specific
• Express settings & Middlewares
Express Routers - Advanced
• var router = express.Router(optionsObj)
• caseSensitive
• strict
• /foo and /foo/ same by def...
Nesting Routers
• var router1 = express.Router(optionsObj)
• var router2 = express.Router(optionsObj)
• router1.get(‘/user...
Multiple Environments
• Common configuration
• Environment specific
• development
• production
• Environment variables + c...
What can you configure?
• DB urls
• application urls
• social media integration
• Anything and everything
Middlewares
• Extension, without inheritance
• Layered approach
• Decide if ok to proceed
• or skip to error
Code Along
Step 11 - Use nested routers
Step 12 - Understanding middlewares
Step 11 – Use nested routers
• Create stocks.routes.js, user.routes.js
• var express = require(‘express’);
• var router = ...
Step 12 – Understanding
Middleware
• function(req, res) {}
• function(req, res, next) {}
• What’s next?
• Common Error Han...
Configuration in NodeJS
• JSON Config files
• One per environment, one global
• Set environment variable before running ap...
A note about authentication
• Don’t reinvent the wheel
• Connect -> Middleware for common use cases
• Passport -> Out of t...
Agenda
• Working with MongoDB & SQL
• Build & Deploy
• Best Practices
• Further Readings
Using Databases
• MongoDB -> JSON object store
• SQL -> not natively JSON
• Use ORMs when possible
When does NoSQL make
sense?
• Non relational data
• Transactions not required
• Atomic, single document commits
• Fast!!!
...
Mongoose for MongoDB
• ORM layer for MongoDB
• Define
• Schemas
• Validations
• Pre/post save hooks
• Querying capabilities
Code Along
Step 13 - Switch to MongoDB
Step 13 – Using MongoDB
• Create Schemas & Models (stocks.model.js)
• var StockSchema = new mongoose.Schema({// def //})
•...
SQL in NodeJS
• Sequelize
• BookshelfJS
• Both offer no MSSQL support
• msnodesql
• node-odbc
• mssql-orm
Debugging NodeJS
• WebStorm
• Debug mode
• Create run configurations
• Start debugging
• Add breakpoints
Debugging NodeJS
• http://nodejs.org/api/debugger.htm
• Manually
– Add debugger statement to code
– Run using node debug i...
Build & Deploy
• Grunt / Gulp
• Run the tests before deploying
• No node_modules
• Ship entire folder
• Run npm install at...
Structuring your Express Codebase
• Folders
– api
• route level
• controller, spec, model, routes
– auth
• routes
• strate...
Keeping the server running
• NodeJS crashes and stops
• Use forever
• Or an external process to keep restarting it
Best Practices
• Structure, modules
• Parallelize when possible
• Think about it at every step
• Use libraries like async,...
Best Practices
• Follow the callback pattern
• Don’t break the err, data structure in your code
• Watch out for async beha...
Other Useful Libraries
• async
• underscore
• RabbitMQ – for Queues and RPC Servers
• SocketIO / SockJS
Code Along
Socket based NodeJS App
AngularJS + NodeJS Chat App
• Setup Socket Listeners and Posters on NodeJS
• Using SocketIO
• Client side already setup
• ...
Further Reading
• Clusters
• RabbitMQ
• SocketIO
• vasync
• More observable, async
• restify
• Pure RESTful services, not ...
Cluster Example
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
i...
Cluster Example - continued
else {
// Workers can share any TCP connection
// In this case its a HTTP server
http.createSe...
How it works
• Child processes spawned using fork
• Communicate with parent using IPC
• Pass server handles back and forth...
In summary
Thank you
• Contact
• shyam@hopscotch.in
• @omniscient1
• Come join me at Hopscotch if you want to work
on exciting stuff ...
Hopscotch in Brief
• Customer focused, Content oriented, discovery oriented shopping experience for moms!
• Not an Amazon/...
Upcoming SlideShare
Loading in …5
×

NodeJS @ JSFoo 2015

NodeJS Workshop for JS Foo 2015

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

  • Be the first to like this

NodeJS @ JSFoo 2015

  1. 1. NodeJS JsFoo!
  2. 2. Wifi Details • SSID: • HasGeek • HasGeek-Wifi • Password: • geeksrus
  3. 3. About me • Currently Head of Engineering @ Hopscotch • Xoogler • Entrepreneur • Corporate Trainer • Author • AngularJS & AngularJS Up & Running for O’Reilly • MBA • Geek!
  4. 4. Agenda • 1 day • Smaller, multiple sessions • Code Along • As fast or slow as needed • Questions, interrupt any time
  5. 5. Agenda - Continued • Introduction • JS on the Server • NodeJS Concepts • Starting NodeJS • NPM & Requires
  6. 6. Agenda - Continued • Working with Node packages • Async • Express • Routes & Config • NPM & Requires
  7. 7. Agenda - Continued • Middleware • Working with MongoDB • Build & Deploy • Sockets?
  8. 8. Requirements • NodeJS (http://nodejs.org) • A good IDE (Recommend Webstorm)
  9. 9. Getting the Code Base http://is.gd/nodejsfoo
  10. 10. The Basics
  11. 11. Agenda • Introduction • JS On the Server & Evolution • NodeJS - How it works • Basic Concepts and Terminologies • Hello NodeJS • NPM & Requires
  12. 12. Evolution of Server side programming • CGI / Perl • Java / ASP • Ruby, PHP, Python • Move towards reusable, maintainable, fast • MVC, Components
  13. 13. Why JS on the server side sounds crazy! Single Threaded Slow, Clunky No OO! No Type Safety
  14. 14. What changed? libev V8 • Event Engine • Non blocking • Core underlying NodeJS • JS Engine • From Chromium • Super Fast!
  15. 15. So what is NodeJS? Not a programming language, but not simply a framework either. For servers as well as for scripts!
  16. 16. Core NodeJS Concepts Event Loop! Non blocking Single Threaded Callbacks FTW!
  17. 17. A Thinking Paradigm Shift teams = teamsDb.getTeams(); for (var i = 0; i < teams.size(); i++) { team = teams.get(i); team.setExtraInfo( teamsDb.getTeamExtraInfo(team.getId()); } return teams;
  18. 18. How would we speed it up? • Threading? • Parallelization? • Identifying the bottlenecks
  19. 19. What if? • teamDb.getTeams was asynchronous • teamDb.getTeams(function(teams) {}); • Same for teamDb.getTeamExtraInfo • teamDb.getTeamExtraInf(function(team) {});
  20. 20. A Thinking Paradigm Shift teamsDb.getTeams(function(teams) { for (var i = 0; i < teams.size(); i++) { team = teams.get(i); teamsDb.getTeamExtraInfo(team.getId(), function(teamExtra) { team.setTeamExtraInfo(teamExtra); }); } // return teams; ????? });
  21. 21. Now what about NodeJS? • Callback oriented • Forced to think about what to do about callback • Forces you to think if you need to wait for it or continue • Parallel friendly approach —> Default
  22. 22. Installing Node • Directly, from nodejs.org • Using nvm – Node Version Manager – Easier to update, and switch versions
  23. 23. When to use NodeJS? • IO intensive – File, DB • Web Servers – More concurrent connections, cheaper! • Scripts / Tools – Command line toolbelt
  24. 24. When to avoid NodeJS • CPU intensive • Long running synchronous tasks • Mathematical Operations – Floating Numbers
  25. 25. So how do we start? • Hello world example
  26. 26. Code-along starts now
  27. 27. Github Repo http://is.gd/nodejsfoo
  28. 28. Code Along – Initial Setup Checkout: git clone https://github.com/Fundoo- Solutions/nodejsfoo.git cd nodejsfoo
  29. 29. Code Along Step 1 - Simple Hello World Step 2 - Handling Arguments & Inputs Step 3 - Using Inbuilt Libraries Step 4 - Event Handling & Callbacks Step 5 - Sharing Logic Between Files
  30. 30. Step 1 – Simple Hello World • console.log • With multiple arguments • Running it • node <filename>
  31. 31. Step 2 - Handling Arguments and Inputs • process.argv • First two arguments • node • filename • Then • arguments in order from command line • array of strings
  32. 32. Step 3 – Inbuilt Libraries - fs • Pull in libraries using • require() • require(‘fs’); • fs.readFileSync(filename, encoding); • fs.readFile is better! • Read as pure string!
  33. 33. Step 4 – Event handling and callbacks • var stream = fs.createReadStream(filename) • stream.on(‘data’, function(data) {}) • stream.on(‘end’, function() {}) • stream.on(‘error’, function(err) {})
  34. 34. Step 5 – Sharing logic between files • module.exports = {getStocks:} • require • Starting with ./ for relative! • fs.readFile • Pass callback for async activity finish!
  35. 35. Core Inbuilt Libraries • fs • http • url
  36. 36. What about? • Sockets • Web Servers • Configuration • Database / ORM • Something else?
  37. 37. Introducing NPM • Node Package Manager • Equivalent to Maven in Java • Comprises • package.json • Global + local packages
  38. 38. How many NPM Packages are out there? 1,80,000+
  39. 39. How does a package.json look like? { "name": ”DEMO App", "description": "DEMO App for Workshop", "version": "0.0.1", "private": true, "engines": { "node": "0.10.x", "npm": "1.3.x" }, "dependencies": { "express" : "4.1.1", "body-parser" : "1.0.2", … } }
  40. 40. Installing a package npm install package-name
  41. 41. Installing a global package npm install –g package-name
  42. 42. Installing all packages for a project npm install (assuming a package.json file)
  43. 43. Installing a package & saving it to package.json npm install --save package-name
  44. 44. Start to server
  45. 45. Agenda • Working with Node packages • NPM & Requires • Async • Express • Routes & Config
  46. 46. How does a package.json look like? { "name": ”DEMO App", "description": "DEMO App for Workshop", "version": "0.0.1", "private": true, "engines": { "node": "0.10.x", "npm": "1.3.x" }, "dependencies": { "express" : "4.1.1", "body-parser" : "1.0.2", … } }
  47. 47. Package.json syntax & versioning • MAJOR.MINOR.PATCH • “primus”: “1.2.3” • Specific • *, x - wildcard support • “async”: “*” • ~ - Atleast, in this minor release • “async”: “~0.8.1” • >= 0.8.1 • < 0.9.0
  48. 48. Package.json syntax & versioning • ^ - More relaxed versioning • “async” : “^0.8.0” • >= 0.8.0 • < 1.0.0 • Recommendation: • Use ^, the default
  49. 49. Package.json – Dependencies vs Dev Dependencies • dependencies • Always needed • Production! • devDependencies • Same syntax • Installed unless NODE_ENV=production
  50. 50. npm Scripts • scripts: {} • test, start, whateveryouwant • Shell commands • echo “Deploying…” • node index.js • Shortcuts • Run using npm run
  51. 51. async • For easier dealing with multiple asynchronous calls • Point in case, async.parallel • An array or object with functions • Each function takes a callback as parameter • Once all functions are done, proceeds to a final block
  52. 52. Code Along Step 6 - Init your package.son Step 7 - Install and use async
  53. 53. Step 6 - Initing Package.son npm init (And answer all the questions)
  54. 54. Step 7 – Use async • npm install --save async • Understanding async parallel • read files in async.parallel • Do composite work in final callback
  55. 55. Express • A web server framework for NodeJS • The de-facto web server for most NodeJS apps • The E in MEAN stack • Configurable, extensible • Middleware based plugins
  56. 56. Express Components Routing Handlers Middlewares Templating / Rendering
  57. 57. Creating an Express NodeJS App If from scratch (npm install –g express) express init
  58. 58. AngularJS + Express? Use the angular-fullstack Yeoman generator
  59. 59. Express Router • app. • get • post • put • delete • patch • and more…
  60. 60. Express Handlers • function(req, res) {} • function(req, res, next) {} • What’s next? • function(err, req, res, next) {}
  61. 61. Code Along Step 8 - Start an express app Step 9 - Create routes and handlers Step 10 - Handling post requests
  62. 62. Step 8 – Start Express App • npm install --save express • var express = require(‘express’); • var app = express(); • app.listen(port, function() {}); • app.get(‘/’, function(req, res) {});
  63. 63. Step 9 – Create routes and handlers • Move logic into get(‘/) • res.send(json); • or res.json(json); • Parametrized get (‘/:id’) • Access using req.params.id • res.status(400) if not found, along with json payload
  64. 64. Step 10 – Handling post routes • npm install --save body-parser • app.use(bodyParser.urlencoded({extended: true})); • app.use(bodyParser.json()); • app.use(express.static(__dirname + '/public')); • app.post('/register', function(req, res) {}); • req.body • Watch out for ordering of routes and collisions!
  65. 65. Express Configuration • Environment based • Global + Environment Specific • Express settings & Middlewares
  66. 66. Express Routers - Advanced • var router = express.Router(optionsObj) • caseSensitive • strict • /foo and /foo/ same by default • router.use • router.get / post / … • app.use(‘/api/test’, router);
  67. 67. Nesting Routers • var router1 = express.Router(optionsObj) • var router2 = express.Router(optionsObj) • router1.get(‘/user’, …) • router1.post(‘/user’/, …) • router2.use(‘/api’, router1); • /api/user routes will be created
  68. 68. Multiple Environments • Common configuration • Environment specific • development • production • Environment variables + configured constants • Secure Info -> Environment Variables • Otherwise, in code, checked in
  69. 69. What can you configure? • DB urls • application urls • social media integration • Anything and everything
  70. 70. Middlewares • Extension, without inheritance • Layered approach • Decide if ok to proceed • or skip to error
  71. 71. Code Along Step 11 - Use nested routers Step 12 - Understanding middlewares
  72. 72. Step 11 – Use nested routers • Create stocks.routes.js, user.routes.js • var express = require(‘express’); • var router = express.Router() • router.get(‘/’, function(req, res) {}); • module.exports = function(app) { app.use(‘/path’, router); }
  73. 73. Step 12 – Understanding Middleware • function(req, res) {} • function(req, res, next) {} • What’s next? • Common Error Handling • function(err, req, res, next) {} • Ordering is important!
  74. 74. Configuration in NodeJS • JSON Config files • One per environment, one global • Set environment variable before running app • Read from process.env • Load file • export
  75. 75. A note about authentication • Don’t reinvent the wheel • Connect -> Middleware for common use cases • Passport -> Out of the box authentication framework for NodeJS & Express • Support for DB backed • FB, Google, Twitter OAuth • And more!
  76. 76. Agenda • Working with MongoDB & SQL • Build & Deploy • Best Practices • Further Readings
  77. 77. Using Databases • MongoDB -> JSON object store • SQL -> not natively JSON • Use ORMs when possible
  78. 78. When does NoSQL make sense? • Non relational data • Transactions not required • Atomic, single document commits • Fast!!! • Document store
  79. 79. Mongoose for MongoDB • ORM layer for MongoDB • Define • Schemas • Validations • Pre/post save hooks • Querying capabilities
  80. 80. Code Along Step 13 - Switch to MongoDB
  81. 81. Step 13 – Using MongoDB • Create Schemas & Models (stocks.model.js) • var StockSchema = new mongoose.Schema({// def //}) • var StockModel = mongoose.model(‘Stock’, StockSchema); • Export it • Controller • Require model, and use find and findOne • Same callback structure • index.js • mongoose.connect('mongodb://jsfoo:jsfoo2015@ds049997.mongolab.com:4999 7/nodejsfoo')
  82. 82. SQL in NodeJS • Sequelize • BookshelfJS • Both offer no MSSQL support • msnodesql • node-odbc • mssql-orm
  83. 83. Debugging NodeJS • WebStorm • Debug mode • Create run configurations • Start debugging • Add breakpoints
  84. 84. Debugging NodeJS • http://nodejs.org/api/debugger.htm • Manually – Add debugger statement to code – Run using node debug index.js – c, n, s, o • continue, next, step in, out – repl • evaluate commands on the fly
  85. 85. Build & Deploy • Grunt / Gulp • Run the tests before deploying • No node_modules • Ship entire folder • Run npm install at installation location • Point at main entry point • Environment driven!
  86. 86. Structuring your Express Codebase • Folders – api • route level • controller, spec, model, routes – auth • routes • strategies • common – config • passport • express • environment based – views – components
  87. 87. Keeping the server running • NodeJS crashes and stops • Use forever • Or an external process to keep restarting it
  88. 88. Best Practices • Structure, modules • Parallelize when possible • Think about it at every step • Use libraries like async, underscore • Search for existing npm packages • Use Middlewares • over calling functions in controllers and handlers • ^ or ~ versions in package.json • Otherwise keep it up to date on a monthly basis
  89. 89. Best Practices • Follow the callback pattern • Don’t break the err, data structure in your code • Watch out for async behavior within loops • Closure, but extract functions instead of inline • Use javascriptlint • or something similar • Use forever, nodemon, or something similar • To ensure your app doesn’t crash and burn • Can use it locally as well Restart on file change
  90. 90. Other Useful Libraries • async • underscore • RabbitMQ – for Queues and RPC Servers • SocketIO / SockJS
  91. 91. Code Along Socket based NodeJS App
  92. 92. AngularJS + NodeJS Chat App • Setup Socket Listeners and Posters on NodeJS • Using SocketIO • Client side already setup • io.on(‘connection’, function(socket) {}); • socket.on(‘event’, function(data) {}); • io.emit(‘event’, data) • broadcast to all!
  93. 93. Further Reading • Clusters • RabbitMQ • SocketIO • vasync • More observable, async • restify • Pure RESTful services, not web apps
  94. 94. Cluster Example var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log('worker ' + worker.process.pid + ' died'); }); }
  95. 95. Cluster Example - continued else { // Workers can share any TCP connection // In this case its a HTTP server http.createServer(function(req, res) { res.writeHead(200); res.end("hello worldn"); }).listen(8000); }
  96. 96. How it works • Child processes spawned using fork • Communicate with parent using IPC • Pass server handles back and forth • Server.listen in child • Serializes arguments • Passes to master process • Handle to server created or passed to child • OS responsible for load balancing across processes sharing same resource
  97. 97. In summary
  98. 98. Thank you • Contact • shyam@hopscotch.in • @omniscient1 • Come join me at Hopscotch if you want to work on exciting stuff with a great company! • WE ARE HIRING!
  99. 99. Hopscotch in Brief • Customer focused, Content oriented, discovery oriented shopping experience for moms! • Not an Amazon/Flipkart model • Vertical focused • Great leadership team • Harvard, INSEAD, Amazon, Google… • Amazing investors • Eduardo (FB Co-founder), Velos Partners, and more! • Customer focused, smart and rapid growth • 20-30% month on month! • Scrappy, hacker oriented culture • Come be a part of something awesome!

    Be the first to comment

NodeJS Workshop for JS Foo 2015

Views

Total views

179

On Slideshare

0

From embeds

0

Number of embeds

0

Actions

Downloads

2

Shares

0

Comments

0

Likes

0

×