SlideShare a Scribd company logo
Node.js with Express
web application framework for node
Gergely Nemeth
What is Express?
get '/' do
redirect to('/hello/World' )
end
get '/hello/:name' do
"Hello #{params[:name]}!"
end
Gergely Nemeth
● Node.js web framework
● Sinatra-inspired
Getting started
Gergely Nemeth
● npm install express
var express = require('express');
var app = express();
app.get('/hello', function(req, res){
res.send('Hello World');
});
app.listen(3000);
console.log('Listening on port 3000');
Getting started #2
Gergely Nemeth
● npm install -g express
● express --sessions --css stylus --ejs myapp
● create : myapp
create : myapp/package.json
create : myapp/app.js
create : myapp/public
create : myapp/public/javascripts
create : myapp/public/images
create : myapp/public/stylesheets
create : myapp/public/stylesheets/style.styl
create : myapp/routes
create : myapp/routes/index.js
create : myapp/views
create : myapp/views/index.ejs
Configuration
Gergely Nemeth
Used to separate production/development/etc...
configurations (based on NODE_ENV)
// all environments
app.configure(function(){
app.set('title', 'Rescue');
})
// development only
app.configure('development', function(){
app.set('mongoUrl', 'localhost/dev');
})
// production only
app.configure('production', function(){
app.set('mongoUrl', 'n.n.n.n/prod');
})
Middlewares
Gergely Nemeth
● logging, auth, gzip, csrf protection, session
management, etc...
● called sequentially, next() callback can trigger the next
middleware
//built-in middlewares
app.use(express.logger());
app.use(express.compress());
app.use(express.methodOverride());
app.use(express.bodyParser());
//custom error handling
app.use(function onError(err, req, res, next) {
//do something with the error
next(err);
});
Routing
Gergely Nemeth
app.VERB(path, [callback...], callback)
● GET, POST, PUT, DELETE, PATCH
● [callback...] are middlewares
app.get(/^/commits/(w+)(?:..(w+))?$/, function(req, res){
var from = req.params[0];
var to = req.params[1] || 'HEAD';
res.send('commit range ' + from + '..' + to);
});
Sessions
Gergely Nemeth
● With middlewares
app.use(express.cookieParser()); app.
use(express.cookieParser('some
secret'));
● For authentication use:
○ Passportjs
○ Everyauth
Rendering
Gergely Nemeth
● With template engines: Mustache(hogan), Jade,
EJS...
● Layout, views, partials
● Variables are passed to the render engine
app.get('/', function(req, res) {
res.locals = {
title: 'Title',
};
return res.render(
'index',
{
partials:
{
part: 'part',
}
}
);
});
Rendering #2
Gergely Nemeth
● part.html
<h1>{{ title }}</h1>
● index.html
{{> part}}
Hello world!

More Related Content

PDF
Node, express & sails
PPT
Nodejs - Building a RESTful API
PDF
Nodejs
PDF
Why NodeJS
PDF
New World of Angular (v2+)
PPTX
Node js training (1)
PPTX
Getting started with node.js
PPTX
Node js for beginners
Node, express & sails
Nodejs - Building a RESTful API
Nodejs
Why NodeJS
New World of Angular (v2+)
Node js training (1)
Getting started with node.js
Node js for beginners

What's hot (20)

PDF
NodeSummit - MEAN Stack
PDF
Complete MVC on NodeJS
PDF
Understand How Node.js and Core Features Works
PDF
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PPTX
PHP Indonesia - Nodejs Web Development
PDF
Introduction to REST API with Node.js
PPTX
Node.Js: Basics Concepts and Introduction
PDF
Webconf nodejs-production-architecture
PPTX
PPTX
Nodejs getting started
PDF
JavaScript Engine and WebAssembly
PPTX
Node js Introduction
PDF
MEAN Stack WeNode Barcelona Workshop
PDF
MEAN Stack - Google Developers Live 10/03/2013
PDF
Introduction to node js - From "hello world" to deploying on azure
PDF
Best node js course
PPTX
3 Things Everyone Knows About Node JS That You Don't
PDF
Bower & Grunt - A practical workflow
PPTX
Introduction to node.js by jiban
PPTX
Node js introduction
NodeSummit - MEAN Stack
Complete MVC on NodeJS
Understand How Node.js and Core Features Works
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PHP Indonesia - Nodejs Web Development
Introduction to REST API with Node.js
Node.Js: Basics Concepts and Introduction
Webconf nodejs-production-architecture
Nodejs getting started
JavaScript Engine and WebAssembly
Node js Introduction
MEAN Stack WeNode Barcelona Workshop
MEAN Stack - Google Developers Live 10/03/2013
Introduction to node js - From "hello world" to deploying on azure
Best node js course
3 Things Everyone Knows About Node JS That You Don't
Bower & Grunt - A practical workflow
Introduction to node.js by jiban
Node js introduction
Ad

Viewers also liked (18)

PDF
Node.js with express
PPTX
Erick Belluci Tedeschi - Segurança em WordPress
PDF
PPT
KEY
Express Presentation
PPT
Building your first Node app with Connect & Express
PPTX
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
PDF
Node Architecture and Getting Started with Express
PDF
TDD a REST API With Node.js and MongoDB
PDF
Node JS Express: Steps to Create Restful Web App
PPTX
Rest api with node js and express
PDF
PPTX
Node JS Express : Steps to Create Restful Web App
PDF
All aboard the NodeJS Express
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
PPTX
Create Rest API in Nodejs
PPTX
Diving into Node with Express and Mongo
PDF
Express node js
Node.js with express
Erick Belluci Tedeschi - Segurança em WordPress
Express Presentation
Building your first Node app with Connect & Express
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Node Architecture and Getting Started with Express
TDD a REST API With Node.js and MongoDB
Node JS Express: Steps to Create Restful Web App
Rest api with node js and express
Node JS Express : Steps to Create Restful Web App
All aboard the NodeJS Express
Workshop 4: NodeJS. Express Framework & MongoDB.
Create Rest API in Nodejs
Diving into Node with Express and Mongo
Express node js
Ad

Similar to Node.js with Express (20)

PDF
Deploy node.js app with capistrano
PDF
Node.jsやってみた
PDF
Quest for the Perfect Workflow for McrFRED
PDF
Nodejs first class
PDF
JLPDevs - Optimization Tooling for Modern Web App Development
PPTX
Building Web Apps with Express
PDF
Build Web Apps using Node.js
PPTX
Introduction to node.js
PDF
OSDC.no 2015 introduction to node.js workshop
PDF
Intro to node.js web apps
PPTX
Kraken
PPTX
Grunt - The JavaScript Task Runner
PDF
May The Nodejs Be With You
PPTX
MunichJS - node.js - from the beginning
PDF
Building websites with Node.ACS
PDF
Building websites with Node.ACS
PDF
Build web application by express
PDF
Web development tools { starter pack }
PDF
The NERD stuff - opening for Domino to the modern web developer
PPTX
Home sensor prototype on Arduino & Raspberry Pi with Node.JS
Deploy node.js app with capistrano
Node.jsやってみた
Quest for the Perfect Workflow for McrFRED
Nodejs first class
JLPDevs - Optimization Tooling for Modern Web App Development
Building Web Apps with Express
Build Web Apps using Node.js
Introduction to node.js
OSDC.no 2015 introduction to node.js workshop
Intro to node.js web apps
Kraken
Grunt - The JavaScript Task Runner
May The Nodejs Be With You
MunichJS - node.js - from the beginning
Building websites with Node.ACS
Building websites with Node.ACS
Build web application by express
Web development tools { starter pack }
The NERD stuff - opening for Domino to the modern web developer
Home sensor prototype on Arduino & Raspberry Pi with Node.JS

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Tartificialntelligence_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mushroom cultivation and it's methods.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
1. Introduction to Computer Programming.pptx
Programs and apps: productivity, graphics, security and other tools
cloud_computing_Infrastucture_as_cloud_p
Tartificialntelligence_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative study of natural language inference in Swahili using monolingua...
Univ-Connecticut-ChatGPT-Presentaion.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Mushroom cultivation and it's methods.pdf
Approach and Philosophy of On baking technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm

Node.js with Express

  • 1. Node.js with Express web application framework for node Gergely Nemeth
  • 2. What is Express? get '/' do redirect to('/hello/World' ) end get '/hello/:name' do "Hello #{params[:name]}!" end Gergely Nemeth ● Node.js web framework ● Sinatra-inspired
  • 3. Getting started Gergely Nemeth ● npm install express var express = require('express'); var app = express(); app.get('/hello', function(req, res){ res.send('Hello World'); }); app.listen(3000); console.log('Listening on port 3000');
  • 4. Getting started #2 Gergely Nemeth ● npm install -g express ● express --sessions --css stylus --ejs myapp ● create : myapp create : myapp/package.json create : myapp/app.js create : myapp/public create : myapp/public/javascripts create : myapp/public/images create : myapp/public/stylesheets create : myapp/public/stylesheets/style.styl create : myapp/routes create : myapp/routes/index.js create : myapp/views create : myapp/views/index.ejs
  • 5. Configuration Gergely Nemeth Used to separate production/development/etc... configurations (based on NODE_ENV) // all environments app.configure(function(){ app.set('title', 'Rescue'); }) // development only app.configure('development', function(){ app.set('mongoUrl', 'localhost/dev'); }) // production only app.configure('production', function(){ app.set('mongoUrl', 'n.n.n.n/prod'); })
  • 6. Middlewares Gergely Nemeth ● logging, auth, gzip, csrf protection, session management, etc... ● called sequentially, next() callback can trigger the next middleware //built-in middlewares app.use(express.logger()); app.use(express.compress()); app.use(express.methodOverride()); app.use(express.bodyParser()); //custom error handling app.use(function onError(err, req, res, next) { //do something with the error next(err); });
  • 7. Routing Gergely Nemeth app.VERB(path, [callback...], callback) ● GET, POST, PUT, DELETE, PATCH ● [callback...] are middlewares app.get(/^/commits/(w+)(?:..(w+))?$/, function(req, res){ var from = req.params[0]; var to = req.params[1] || 'HEAD'; res.send('commit range ' + from + '..' + to); });
  • 8. Sessions Gergely Nemeth ● With middlewares app.use(express.cookieParser()); app. use(express.cookieParser('some secret')); ● For authentication use: ○ Passportjs ○ Everyauth
  • 9. Rendering Gergely Nemeth ● With template engines: Mustache(hogan), Jade, EJS... ● Layout, views, partials ● Variables are passed to the render engine app.get('/', function(req, res) { res.locals = { title: 'Title', }; return res.render( 'index', { partials: { part: 'part', } } ); });
  • 10. Rendering #2 Gergely Nemeth ● part.html <h1>{{ title }}</h1> ● index.html {{> part}} Hello world!