SlideShare a Scribd company logo
Intro to node.js Web Apps
#SKGNode
#SKGNode
Core Concepts
#SKGNode
Why Node?
● Asynchronous
● Robust
● Blazingly FAST
● Javascript / Browserify
● Largest growth year over year
● Largest frontend tool belt
#SKGNode
Philosophy
● No Frameworks
● Small reusable libraries
● NPM
● Open Source
#SKGNode
A Typical Node Web App
Your AppCore HTTP ExpressJS
#SKGNode
Quick Start
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
#SKGNode
Every Callback is a Middleware
Middleware
#SKGNode
Anatomy of a Middleware
app.get(‘/’, function(req, res, next) {/*..
*/});
Request
Object
Response
Object
Pass
Control
#SKGNode
The Request Object
● Instantiates per request
● Carries all request information
○ Headers
■ Cookies
○ Request route
○ Parameters (/user/:id), Body, Query
● Propagates Information (i.e. session, auth)
#SKGNode
The Response Object
● Instantiates per request
● Carries all respond methods
● Can be build iteratively (CORS, HTTP Code)
● Can terminate a Request
○ .render(), .send(), .end()
○ No ‘next()’ invocation is required
#SKGNode
The Flow Control next()
● Express depends on Middleware arity
● If omitted the middleware is Synchronous
● If truthy value is passed fails the request
○ next(‘no go’);
● Invoke once -and only once- to go to next
● If middleware is Terminal do not include it
(i.e. final controller call that renders)
#SKGNode
The final route will never be
reached!
app.use(express.static(__dirname + '/public'));
app.use(logger());
app.use(function(req, res){
res.send('Hello');
});
app.get(‘/’, function(req, res){
res.send('World');
});
Sequence MATTERS
Static assets will get served
without generating a Log
#SKGNode
Working with Middleware
#SKGNode
Augmenting the Request
app.use(function(req, res, next) {
redis.get(req.cookies.id, function(err, result) {
if (err) { // bail out
next(err);
return;
}
req.user = result; // augmentation
next();
});
});
#SKGNode
// Protect an auth only route
app.get(‘/profile’, function(req, res, next) {
if (!req.user) {
res.status(401).send(‘No go dude’);
return; // .send() is a terminal action
// no need to call next
});
next(); // Client is authed, go on...
});
Leveraging Augmentation
#SKGNode
Express maintained Middleware
● body-parser
● compression
● cookie-parser
● csurf (CSRF)
● errorhandler
● express-session
https://github.com/senchalabs/connect#middleware
#SKGNode
Routing
#SKGNode
HTTP Verbs
● app.use(fn) Catches all!
● app.all(route, fn) Catches all!
● app.get(route, fn)
● app.put(route, fn)
● app.post(route, fn)
● app.delete(route, fn)
● app.head(route, fn)
#SKGNode
app.get([string|Regex],
[Function|Array], ...args)
app.get(‘/’, showFrontPage);
app.get(‘/’, fn1, fn2);
app.get(‘/’, [fn1, fn2]);
HTTP Verb Syntax
#SKGNode
Routing Options
RegEx /^/commits/
(w+)/
“/commits/sdjeo34” → req.params[0] === ‘sdjeo34’
Plain String
‘/’
Triggers on “/”, “/?id=12”, etc
Parametric String
‘/user/:id’
Triggers on “/user/thanpolas” → req.params.id === ‘thanpolas’
Multi Parametric String
‘/user/:network/:id’
Triggers on “/user/skgNode/thanpolas” → req.params.network
Catch All
‘/api/*’
Catches all routes under “/api/”
#SKGNode
Routing Best Practices
● Routing is where the buck stops at
● Decouple your routes from your core app
● Study the app.route() pattern
● At the end, there can only be a 404
#SKGNode
Views
#SKGNode
Defining Paths & Engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
Check out all available template engines:
https://github.com/visionmedia/express/wiki#template-engines
#SKGNode
Rendering a View
/* GET home page. */
router.get('/', function(req, res) { // no next required
res.render('index', { title: ‘SKGNode’ });
});
extends layout
block content
h1= title
p Welcome to #{title}
Thank you!
Thanasis Polychronakis
@thanpolas
thanpolas@gmail.com #SKGNode
Questions?
Thanasis Polychronakis
@thanpolas
thanpolas@gmail.com #SKGNode

More Related Content

What's hot (20)

PPTX
Security testing of YUI powered applications
dimisec
 
PPTX
Angularjs Performance
Steven Lambert
 
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Binary Studio
 
PDF
"this" in JavaScript
Martha Schumann
 
PDF
Angular Promises and Advanced Routing
Alexe Bogdan
 
PDF
NoSQL Injections in Node.js - The case of MongoDB
Sqreen
 
PDF
Introduction to AngularJS
Pat Cito
 
PDF
Architecture, Auth, and Routing with uiRouter
Christopher Caplinger
 
PPTX
Dart and AngularDart
Loc Nguyen
 
PDF
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
Fwdays
 
PPTX
UI-Router
Loc Nguyen
 
PDF
Ember.js - A JavaScript framework for creating ambitious web applications
Juliana Lucena
 
PDF
Asynchronous Programming with JavaScript
WebF
 
KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
DOCX
Spring 3.0
Ved Prakash Gupta
 
PDF
React.js or why DOM finally makes sense
Eldar Djafarov
 
PDF
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
 
PDF
MVC-RS par Grégoire Lhotelier
CocoaHeads France
 
PDF
Excellent
Marco Otte-Witte
 
Security testing of YUI powered applications
dimisec
 
Angularjs Performance
Steven Lambert
 
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Binary Studio
 
"this" in JavaScript
Martha Schumann
 
Angular Promises and Advanced Routing
Alexe Bogdan
 
NoSQL Injections in Node.js - The case of MongoDB
Sqreen
 
Introduction to AngularJS
Pat Cito
 
Architecture, Auth, and Routing with uiRouter
Christopher Caplinger
 
Dart and AngularDart
Loc Nguyen
 
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
Fwdays
 
UI-Router
Loc Nguyen
 
Ember.js - A JavaScript framework for creating ambitious web applications
Juliana Lucena
 
Asynchronous Programming with JavaScript
WebF
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
Spring 3.0
Ved Prakash Gupta
 
React.js or why DOM finally makes sense
Eldar Djafarov
 
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
 
MVC-RS par Grégoire Lhotelier
CocoaHeads France
 
Excellent
Marco Otte-Witte
 

Viewers also liked (6)

PDF
Intro to node.js
Thanos Polychronakis
 
PDF
HowTo Freelance
Thanos Polychronakis
 
PDF
Entities, the theory
Thanos Polychronakis
 
PDF
Business considerations for node.js applications
Aspenware
 
PPTX
NodeJS - Server Side JS
Ganesh Kondal
 
PDF
NodeJS for Beginner
Apaichon Punopas
 
Intro to node.js
Thanos Polychronakis
 
HowTo Freelance
Thanos Polychronakis
 
Entities, the theory
Thanos Polychronakis
 
Business considerations for node.js applications
Aspenware
 
NodeJS - Server Side JS
Ganesh Kondal
 
NodeJS for Beginner
Apaichon Punopas
 
Ad

Similar to Intro to node.js web apps (20)

PPTX
Building Web Apps with Express
Aaron Stannard
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PDF
Build web application by express
Shawn Meng
 
PDF
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
PDF
Kraken Front-Trends
PayPal
 
PPTX
Kraken
PayPal
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PDF
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
PDF
Build Web Apps using Node.js
davidchubbs
 
PDF
node.js practical guide to serverside javascript
Eldar Djafarov
 
PPT
JS everywhere 2011
Oleg Podsechin
 
PDF
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
Hamdi Hmidi
 
PDF
Introduction to REST API with Node.js
Yoann Gotthilf
 
PPT
nodejs tutorial foor free download from academia
rani marri
 
ODP
Node js
hazzaz
 
PPTX
Building and Scaling Node.js Applications
Ohad Kravchick
 
ODP
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
vvaswani
 
PPTX
Express JS
Alok Guha
 
PDF
Node js introduction
Alex Su
 
PPTX
Intro to Node
Aaron Stannard
 
Building Web Apps with Express
Aaron Stannard
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
Build web application by express
Shawn Meng
 
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
Kraken Front-Trends
PayPal
 
Kraken
PayPal
 
Writing robust Node.js applications
Tom Croucher
 
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Build Web Apps using Node.js
davidchubbs
 
node.js practical guide to serverside javascript
Eldar Djafarov
 
JS everywhere 2011
Oleg Podsechin
 
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
Hamdi Hmidi
 
Introduction to REST API with Node.js
Yoann Gotthilf
 
nodejs tutorial foor free download from academia
rani marri
 
Node js
hazzaz
 
Building and Scaling Node.js Applications
Ohad Kravchick
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
vvaswani
 
Express JS
Alok Guha
 
Node js introduction
Alex Su
 
Intro to Node
Aaron Stannard
 
Ad

Recently uploaded (20)

DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 

Intro to node.js web apps