SlideShare a Scribd company logo
 02 | Understanding Module Design Pattern
 03 | Express.js
 Ahmed Assaf | Senior Software Engineer
Setting Expectations
 Target Audience
 Web Developers
 Web Designers
 Developers with experience using other service side languages such as PHP,
ASP.NET, Python, Ruby etc.
Module Overview
 Exports a Namespace
 Exports a Function
 Exports a Higher Order Function
 Exports a Constructor
 Exports a Singleton
 Extends a Global Object
 Applies a Monkey Patch
Module Design Patterns
 Modules are still JavaScript
 Possess many of the challenges of pre-ES6 Javascript
 Design Patterns to help with
 Encapsulation
 Stable Interface
Exports a Namespace
Exports a Namespace
 Module returns an object
 Object contains properties and functions
 Calling code can refer to properties and execute functions
Simply return an object with whatever properties and functions the
calling code should have access to
//private module stuff can happen here
//then return an object
module.exports = {
property1: 'value',
property2: 'value',
function1: function(){ … }
function2: function(){ … }
}
Core 'fs' Node module returns an object
readFile and ReadStream are functions of the returned object
Both are accessible from this calling function
Analogous to static classes and members in other languages
var fs = require('fs');
fs.readFile('./file.txt', function(err, data) {
console.log("readFile contents: '%s'", data);
});
new fs.ReadStream('./file.txt').on('data', function(data) {
console.log("ReadStream contents: '%s'", data);
});
Exports a Function
Exports a Function
 Factory function
 Gives you instancing since all variables are encased in a closure
 Closure is run for each require()
 Revealing Module Pattern you may have used in client side JavaScript
 ProTip
 If you don’t need instancing – export a namespace
 If you need instancing – export a constructor
module.exports = function(options) {
options = options || {};
var loggingLevel = options.loggingLevel || 1;
function logMessage(logLevel, message) {
if(logLevel <= loggingLevel) {
console.log(message);
}
}
return { log: logMessage };
}
DEMO
Exports a Higher Order Function
Exports a Higher Order Function
 Like the former, but also receives a function that affects the behavior of the function it returns
 Express middleware is a great example - functions are provided and the middleware function is returned
Chaining is possible with the app object because the middleware
functions each return it.
var app = require('express')();
app.use('/route1', function(res, req, next) {
//do something
next();
});
app.use('/route2', function(res, req, next) {
//do something
next();
});
Exports a Constructor
Exports a Constructor
 Constructor function creates instance
 Prototype used to define behavior
 Caller creates instance with new keyword
 Multi instance
DEMO
Exports a Singleton
Exports a Singleton
 Instantiates object before returning it
 Causes all calling modules to share a single object instance
When an object is instantiated before it's returned, it acts as a
singleton.
function Something() {
…
}
module.exports = new Something();
Mongoose is one example of a good use of the singleton pattern
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) // ...
console.log('meow');
});
Extends a Global Object
Extends a Global Object
 Modifies an existing type i.e. String
 Doesn’t have to export anything
 Makes for nice calling syntax but can be difficult to track down source in large project
 Frowned upon in open source packages
Applies a Monkey Patch
Applies a Monkey Patch
 A monkey patch is the dynamic modification of a class or object at runtime to fix a bug in existing code
 Similar to previous pattern (extends a global object) but affects cached node modules
The winston logger defaults all profiling statements to the info level
and you can’t change
A quick monkey patch allows you to log data out as any log level you
want and replace the built in functionality without forking the code
base
winston.Logger.prototype.profile = function(id) {
// Altered behvaior or winston loggers profile function
};
Summary
 Exports a Namespace
 Exports a Function
 Exports a Higher Order Function
 Exports a Constructor
 Exports a Singleton
 Extends a Global Object
 Applies a Monkey Patch
 03 | Express.js
What is Express?
 Express is a minimal, open source and flexible node.js web app framework designed to make developing
websites, web apps and APIs much easier.
Why use Express?
 Express helps you respond to requests with route support so that you may
write responses to specific URLs.
 Supports multiple templating engines to simplify generating HTML.
Installing and Using Express
Installing and Using Express
npm install express
npm install jade
Creating a Simple REST API
Explanation of Routes
 A router maps HTTP requests to a callback.
 HTTP requests can be sent as GET/POST/PUT/DELETE, etc.
 URLs describe the location targeted.
 Node helps you map a HTTP GET request like:
 http://localhost:8888/index
 To a request handler (callback)
app.get('/index', function (req, res) {});
Creating a Simple Express Application
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.json({message:'hooray! welcome to our api!'});
});
app.listen(process.env.PORT || 8080);
DEMO
Creating a simple REST API with Express Framework
DEMO
Using the express-generator package.
DEMO
Using Express for Multiple Pages with Query Parameters
Building a RESTful API for Dogs
Resource GET PUT POST DELETE
Collection URI, such
as
http://api.example
.com/v1/dogs/
List all
the
dogs
Replace all the dogs
with a new
collection of dogs.
Create a new
dog in the
collection.
Delete the
entire dog
collection.
Element URI, such
as
http://api.example
.com/v1/dog/1
Get a
specifi
c dog.
Replace a dog in the
collection with
another dog.
Not used.
Delete the dog
from the
collection.
DEMO
Using Express to build a RESTful API
Resources
 Express Framework http://expressjs.com/
 Intro to Express http://code.tutsplus.com/tutorials/introduction-to-express--
net-33367
 Jade Templates http://jade-lang.com/tutorial/
 JavaScript and Jade Templating
http://www.slideshare.net/wearefractal/jade-javascript-templating
Resources
 Using Node.js with Visual Studio Code
 #MVA Course By
 Stacey Mulcahy | Senior Technical Evangelist
 Rami Sayar | Technical Evangelist
 Mastering Node.js Modules #MVA Course By
 Chris Kinsman | Chief Architect at PushSpring
 https://blog.jcoglan.com/2013/03/30/callbacks-are-imperative-promises-are-functional-
nodes-biggest-missed-opportunity/
 http://code.tutsplus.com/tutorials/using-nodes-event-module--net-35941
 http://spin.atomicobject.com/2012/03/14/nodejs-and-asynchronous-programming-with-
promises/
 Github repo: https://github.com/AhmedAssaf/NodeMVA
 From : https://github.com/sayar/NodeMVA

More Related Content

What's hot (20)

PPTX
Express JS
Alok Guha
 
PDF
Expressjs
Yauheni Nikanovich
 
PDF
MongoDB and Node.js
Norberto Leite
 
PPTX
JavaScript Promises
L&T Technology Services Limited
 
PPTX
Introduction to RxJS
Abul Hasan
 
PPTX
Introduction to Node js
Akshay Mathur
 
PPTX
Nodejs functions & modules
monikadeshmane
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PDF
Use Node.js to create a REST API
Fabien Vauchelles
 
PPTX
Express JS
Designveloper
 
PPTX
JavaScript Event Loop
Designveloper
 
PPT
Node.js Express Framework
TheCreativedev Blog
 
PPTX
Rxjs ppt
Christoffer Noring
 
PPT
RESTful API In Node Js using Express
Jeetendra singh
 
PPTX
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
PDF
Introduction to Node.JS Express
Eueung Mulyana
 
PDF
Web Worker, Service Worker and Worklets
Keshav Gupta
 
PPTX
NodeJS guide for beginners
Enoch Joshua
 
PDF
Introduction to Redux
Ignacio Martín
 
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
Express JS
Alok Guha
 
MongoDB and Node.js
Norberto Leite
 
JavaScript Promises
L&T Technology Services Limited
 
Introduction to RxJS
Abul Hasan
 
Introduction to Node js
Akshay Mathur
 
Nodejs functions & modules
monikadeshmane
 
Introduction Node.js
Erik van Appeldoorn
 
Use Node.js to create a REST API
Fabien Vauchelles
 
Express JS
Designveloper
 
JavaScript Event Loop
Designveloper
 
Node.js Express Framework
TheCreativedev Blog
 
RESTful API In Node Js using Express
Jeetendra singh
 
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
Introduction to Node.JS Express
Eueung Mulyana
 
Web Worker, Service Worker and Worklets
Keshav Gupta
 
NodeJS guide for beginners
Enoch Joshua
 
Introduction to Redux
Ignacio Martín
 
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 

Viewers also liked (20)

PPTX
Node JS Express : Steps to Create Restful Web App
Edureka!
 
PDF
Node-IL Meetup 12/2
Ynon Perek
 
PDF
Nodejs mongoose
Fin Chen
 
DOCX
Mongoose getting started-Mongo Db with Node js
Pallavi Srivastava
 
PDF
Getting Started With MongoDB and Mongoose
Ynon Perek
 
PDF
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
PPTX
EAIESB TIBCO EXPERTISE
Vijay Reddy
 
PDF
NodeJS_Presentation
Arpita Patel
 
PPTX
Mule ESB session day 1
kkk_f17
 
PDF
Enterprise Integration Patterns
Oleg Tsal-Tsalko
 
PPT
Managing Patient SatLEADfor4-25-13
alfred lopez
 
PDF
Node JS Express: Steps to Create Restful Web App
Edureka!
 
PDF
Patterns for Enterprise Integration Success
WSO2
 
PDF
Enterprise Integration Patterns
Johan Aludden
 
PDF
Trends und Anwendungsbeispiele im Life Science Bereich
AWS Germany
 
PPTX
Enterprise Integration Patterns
Sergey Podolsky
 
KEY
Mongoose v3 :: The Future is Bright
aaronheckmann
 
PDF
Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...
Kai Wähner
 
PDF
Node js
Rohan Chandane
 
PPT
Implementation in mule esb
Vamsi Krishna
 
Node JS Express : Steps to Create Restful Web App
Edureka!
 
Node-IL Meetup 12/2
Ynon Perek
 
Nodejs mongoose
Fin Chen
 
Mongoose getting started-Mongo Db with Node js
Pallavi Srivastava
 
Getting Started With MongoDB and Mongoose
Ynon Perek
 
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
EAIESB TIBCO EXPERTISE
Vijay Reddy
 
NodeJS_Presentation
Arpita Patel
 
Mule ESB session day 1
kkk_f17
 
Enterprise Integration Patterns
Oleg Tsal-Tsalko
 
Managing Patient SatLEADfor4-25-13
alfred lopez
 
Node JS Express: Steps to Create Restful Web App
Edureka!
 
Patterns for Enterprise Integration Success
WSO2
 
Enterprise Integration Patterns
Johan Aludden
 
Trends und Anwendungsbeispiele im Life Science Bereich
AWS Germany
 
Enterprise Integration Patterns
Sergey Podolsky
 
Mongoose v3 :: The Future is Bright
aaronheckmann
 
Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...
Kai Wähner
 
Implementation in mule esb
Vamsi Krishna
 
Ad

Similar to Module design pattern i.e. express js (20)

PDF
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
PPT
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
PPT
Smoothing Your Java with DSLs
intelliyole
 
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
PDF
[2015/2016] JavaScript
Ivano Malavolta
 
KEY
JavaScript Growing Up
David Padbury
 
PDF
IBM ConnectED 2015 - MAS103 XPages Performance and Scalability
Paul Withers
 
PDF
Divide and Conquer – Microservices with Node.js
Sebastian Springer
 
PPT
React native
Mohammed El Rafie Tarabay
 
PDF
Build Web Apps using Node.js
davidchubbs
 
PDF
Java concurrency
Abhijit Gaikwad
 
PPTX
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
ODP
Workflow Management with Espresso Workflow
Rolf Kremer
 
PDF
Short intro to scala and the play framework
Felipe
 
PPTX
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
PPTX
JavaScript (without DOM)
Piyush Katariya
 
PPTX
Intro to ES6 and why should you bother !
Gaurav Behere
 
PPTX
React Basic and Advance || React Basic
rafaqathussainc077
 
PPTX
react-slides.pptx
DayNightGaMiNg
 
PPTX
Modern frontend in react.js
Abdulsattar Mohammed
 
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Smoothing Your Java with DSLs
intelliyole
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
[2015/2016] JavaScript
Ivano Malavolta
 
JavaScript Growing Up
David Padbury
 
IBM ConnectED 2015 - MAS103 XPages Performance and Scalability
Paul Withers
 
Divide and Conquer – Microservices with Node.js
Sebastian Springer
 
Build Web Apps using Node.js
davidchubbs
 
Java concurrency
Abhijit Gaikwad
 
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
Workflow Management with Espresso Workflow
Rolf Kremer
 
Short intro to scala and the play framework
Felipe
 
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
JavaScript (without DOM)
Piyush Katariya
 
Intro to ES6 and why should you bother !
Gaurav Behere
 
React Basic and Advance || React Basic
rafaqathussainc077
 
react-slides.pptx
DayNightGaMiNg
 
Modern frontend in react.js
Abdulsattar Mohammed
 
Ad

More from Ahmed Assaf (8)

PPTX
Javascript Road Trip(ES6)
Ahmed Assaf
 
PPTX
Javascript Road Trip(es6)
Ahmed Assaf
 
PPTX
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
 
PDF
Certificate_Building Apps with Node.js Jump Start
Ahmed Assaf
 
PDF
Certificate_Using Node.js with Visual Studio Code
Ahmed Assaf
 
PDF
Certificate_MEAN Stack Jump Start
Ahmed Assaf
 
PDF
Certificate_Mastering Node.js Modules and Packages with Visual Studio Code
Ahmed Assaf
 
PDF
Certificate_Developing in HTML5 with JavaScript and CSS3 Jump Start
Ahmed Assaf
 
Javascript Road Trip(ES6)
Ahmed Assaf
 
Javascript Road Trip(es6)
Ahmed Assaf
 
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
 
Certificate_Building Apps with Node.js Jump Start
Ahmed Assaf
 
Certificate_Using Node.js with Visual Studio Code
Ahmed Assaf
 
Certificate_MEAN Stack Jump Start
Ahmed Assaf
 
Certificate_Mastering Node.js Modules and Packages with Visual Studio Code
Ahmed Assaf
 
Certificate_Developing in HTML5 with JavaScript and CSS3 Jump Start
Ahmed Assaf
 

Recently uploaded (20)

PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 

Module design pattern i.e. express js

  • 1.  02 | Understanding Module Design Pattern  03 | Express.js  Ahmed Assaf | Senior Software Engineer
  • 2. Setting Expectations  Target Audience  Web Developers  Web Designers  Developers with experience using other service side languages such as PHP, ASP.NET, Python, Ruby etc.
  • 3. Module Overview  Exports a Namespace  Exports a Function  Exports a Higher Order Function  Exports a Constructor  Exports a Singleton  Extends a Global Object  Applies a Monkey Patch
  • 4. Module Design Patterns  Modules are still JavaScript  Possess many of the challenges of pre-ES6 Javascript  Design Patterns to help with  Encapsulation  Stable Interface
  • 6. Exports a Namespace  Module returns an object  Object contains properties and functions  Calling code can refer to properties and execute functions
  • 7. Simply return an object with whatever properties and functions the calling code should have access to //private module stuff can happen here //then return an object module.exports = { property1: 'value', property2: 'value', function1: function(){ … } function2: function(){ … } }
  • 8. Core 'fs' Node module returns an object readFile and ReadStream are functions of the returned object Both are accessible from this calling function Analogous to static classes and members in other languages var fs = require('fs'); fs.readFile('./file.txt', function(err, data) { console.log("readFile contents: '%s'", data); }); new fs.ReadStream('./file.txt').on('data', function(data) { console.log("ReadStream contents: '%s'", data); });
  • 10. Exports a Function  Factory function  Gives you instancing since all variables are encased in a closure  Closure is run for each require()  Revealing Module Pattern you may have used in client side JavaScript  ProTip  If you don’t need instancing – export a namespace  If you need instancing – export a constructor
  • 11. module.exports = function(options) { options = options || {}; var loggingLevel = options.loggingLevel || 1; function logMessage(logLevel, message) { if(logLevel <= loggingLevel) { console.log(message); } } return { log: logMessage }; }
  • 12. DEMO
  • 13. Exports a Higher Order Function
  • 14. Exports a Higher Order Function  Like the former, but also receives a function that affects the behavior of the function it returns  Express middleware is a great example - functions are provided and the middleware function is returned
  • 15. Chaining is possible with the app object because the middleware functions each return it. var app = require('express')(); app.use('/route1', function(res, req, next) { //do something next(); }); app.use('/route2', function(res, req, next) { //do something next(); });
  • 17. Exports a Constructor  Constructor function creates instance  Prototype used to define behavior  Caller creates instance with new keyword  Multi instance
  • 18. DEMO
  • 20. Exports a Singleton  Instantiates object before returning it  Causes all calling modules to share a single object instance
  • 21. When an object is instantiated before it's returned, it acts as a singleton. function Something() { … } module.exports = new Something();
  • 22. Mongoose is one example of a good use of the singleton pattern var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var Cat = mongoose.model('Cat', { name: String }); var kitty = new Cat({ name: 'Zildjian' }); kitty.save(function (err) { if (err) // ... console.log('meow'); });
  • 24. Extends a Global Object  Modifies an existing type i.e. String  Doesn’t have to export anything  Makes for nice calling syntax but can be difficult to track down source in large project  Frowned upon in open source packages
  • 26. Applies a Monkey Patch  A monkey patch is the dynamic modification of a class or object at runtime to fix a bug in existing code  Similar to previous pattern (extends a global object) but affects cached node modules
  • 27. The winston logger defaults all profiling statements to the info level and you can’t change A quick monkey patch allows you to log data out as any log level you want and replace the built in functionality without forking the code base winston.Logger.prototype.profile = function(id) { // Altered behvaior or winston loggers profile function };
  • 28. Summary  Exports a Namespace  Exports a Function  Exports a Higher Order Function  Exports a Constructor  Exports a Singleton  Extends a Global Object  Applies a Monkey Patch
  • 29.  03 | Express.js
  • 30. What is Express?  Express is a minimal, open source and flexible node.js web app framework designed to make developing websites, web apps and APIs much easier.
  • 31. Why use Express?  Express helps you respond to requests with route support so that you may write responses to specific URLs.  Supports multiple templating engines to simplify generating HTML.
  • 33. Installing and Using Express npm install express npm install jade
  • 34. Creating a Simple REST API
  • 35. Explanation of Routes  A router maps HTTP requests to a callback.  HTTP requests can be sent as GET/POST/PUT/DELETE, etc.  URLs describe the location targeted.  Node helps you map a HTTP GET request like:  http://localhost:8888/index  To a request handler (callback) app.get('/index', function (req, res) {});
  • 36. Creating a Simple Express Application var express = require('express'); var app = express(); app.get('/', function (req, res) { res.json({message:'hooray! welcome to our api!'}); }); app.listen(process.env.PORT || 8080);
  • 37. DEMO Creating a simple REST API with Express Framework
  • 39. DEMO Using Express for Multiple Pages with Query Parameters
  • 40. Building a RESTful API for Dogs Resource GET PUT POST DELETE Collection URI, such as http://api.example .com/v1/dogs/ List all the dogs Replace all the dogs with a new collection of dogs. Create a new dog in the collection. Delete the entire dog collection. Element URI, such as http://api.example .com/v1/dog/1 Get a specifi c dog. Replace a dog in the collection with another dog. Not used. Delete the dog from the collection.
  • 41. DEMO Using Express to build a RESTful API
  • 42. Resources  Express Framework http://expressjs.com/  Intro to Express http://code.tutsplus.com/tutorials/introduction-to-express-- net-33367  Jade Templates http://jade-lang.com/tutorial/  JavaScript and Jade Templating http://www.slideshare.net/wearefractal/jade-javascript-templating
  • 43. Resources  Using Node.js with Visual Studio Code  #MVA Course By  Stacey Mulcahy | Senior Technical Evangelist  Rami Sayar | Technical Evangelist  Mastering Node.js Modules #MVA Course By  Chris Kinsman | Chief Architect at PushSpring  https://blog.jcoglan.com/2013/03/30/callbacks-are-imperative-promises-are-functional- nodes-biggest-missed-opportunity/  http://code.tutsplus.com/tutorials/using-nodes-event-module--net-35941  http://spin.atomicobject.com/2012/03/14/nodejs-and-asynchronous-programming-with- promises/  Github repo: https://github.com/AhmedAssaf/NodeMVA  From : https://github.com/sayar/NodeMVA

Editor's Notes

  • #2: 1
  • #4: After this slide, it’s all demo. See the demo script for the majority of the content
  • #6: ~7 min
  • #10: ~7 min
  • #14: ~7 min
  • #17: ~7 min
  • #20: ~7 min
  • #24: ~7 min
  • #26: ~7 min
  • #29: After this slide, it’s all demo. See the demo script for the majority of the content
  • #30: 29
  • #33: 32
  • #35: 34
  • #39: npm install -g express-generator express /tmp/foo