SlideShare a Scribd company logo
Complete MVC with NodeJS

Hüseyin BABAL
Software Developer, CSM
@Sony Eurasia
Who Am I
Hüseyin BABAL
Software Developer, CSM
@Sony Eurasia

Open Source Comitter
Linux, JAVA, PHP, MongoDB, Javascript, NodeJS, Elasticsearch are my
job 
GDG event speaker
WHAT IS NODE.JS?
NodeJS is a software platform that is
used to build scalable network
applications
●

Author: Ryan Lienhart Dahl

●

Built on Chrome V8 Engine

●

Written in C++, Javascript

●

Sponsored by Joyent
SO,
WHAT IS NODE.JS?
V8 Engine
JS on Server Side
Single Thread
Event Loop

Non-Blocking I/O
WHY TO USE
NODE.JS?
I/O is Expensive
Apache:Memory
usage increases
per connection
Nginx:Constant
memory usage
per connection,
because nginx
uses event loop
mechanism
Dealing with I/O Problems
● Synchronous - One request at a time
● Fork - New process for each request
● Thread - New thread for each request
Thread per request is memory expensive!

What if all threads are busy?
Multithread code is;
● difficult to debug
● difficult to write
● in efficiently performed
How about this answer?

Single thread with non-blocking I/O
WHAT IS EVENT LOOP
AND NON-BLOCKING
I/O?
Blocking I/O
Busy
process

Block process until
job is done

Process
available

Non-Blocking I/O

Event Stack

cb
Do the job and
notify program when
it’s done
Assign jobs to event stack, you will be
notified
One single thread can handle entire
program
Traditional threaded architecture is not
an easy thing
More thread means more process,
equals more memory
Min cost, speed development
Scalable architecture
Callback functions
SEEMS COOL, HOW
ABOUT CODING?
You know JS? Then you
code
NPM (Node Package
Manager)

Available
Windows/Linux/MAC
Webstorm is the best,
also use notepad++
npm install “module_name”

Import module with “require”

File : server.js
Simple web server!!!

node server.js
To test web server, go to url http://127.0.0.1:1337
What about if you try to make a system have such url:
http://127.0.0.1:1337/product/1234.html ???
ANSWER:EXPRESS.JS
Sinatra inspired web development
framework for node.js
HOWTO START?
You have already installed node.js before…
npm install express -g
That’s it! You can use express framework on your
project
Ideal project structure for nodejs
based web applications
Model
{mongoose}
View
{jade}

Controller
{express
built-in fns}
A quick scenario…

● User goes http://127.0.0.1:1337/tickets/devfestticket54332.html
● System fetchs ticket information from db by using
id(54332)
● Assign ticket information to view
● Render view and send to user browser
MODEL DESIGNING
Ticket = new Schema({
tId:{
type:String,
required:true
},
title:{
type:String,
required:true
},
organizationDate:{
type:Date,
required:true
},
owner:{
type:String,
validate:[validator({
length:{
min:3,
max:20
}
}), "username"],
required:false,
default:"anonymous"
}
});

Yes, model definition in json format. Actually, all
the data in nodejs world are in json format.

Model definition is done. This model should be
exists under “models” folder.
Require this model when you need to use

Assume this model defined in a file called
“Ticket.js”
CONTROLLER
*Controller isthe behaviour of your program
*Put your controller definition files under “controller” folder.
VIEW
View files are under “views” folder.
You can use template engines with express.js, in this scenario, “jade” used
Create ticket-detail.jade, put it under “views” folder
Indendation based template engine
COMBINE ALL
Controllers,
Views, Models
managed by main
bootstrap file
called “app.js”

1

2

Go to project
folder and say
3

node app.js
4

5
BEST PRACTICES
WHO USES NODEJS?
Node.js

https://github.com/joyent/node

express.js

https://github.com/visionmedia/express

mongoose

https://github.com/LearnBoost/mongoose

jade

https://github.com/visionmedia/jade

Express Simple Blog

https://github.com/nodejstr/expressSimpleBlog

NodeJS Türkiye

http://www.nodejstr.com/
Questions?
Thank you 

More Related Content

What's hot

What's hot (20)

Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
Express JS Middleware Tutorial
Express JS Middleware TutorialExpress JS Middleware Tutorial
Express JS Middleware Tutorial
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJS
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Express JS
Express JSExpress JS
Express JS
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Working with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCWorking with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVC
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Introduction à l’intégration continue avec Jenkins
Introduction à l’intégration continue avec JenkinsIntroduction à l’intégration continue avec Jenkins
Introduction à l’intégration continue avec Jenkins
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 

Similar to Complete MVC on NodeJS

Node.js.pdf
Node.js.pdfNode.js.pdf
Node.js.pdf
gulfam ali
 

Similar to Complete MVC on NodeJS (20)

Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
Nodejs
NodejsNodejs
Nodejs
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdf
 
An Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureAn Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows Azure
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
 
Node js
Node jsNode js
Node js
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Node.js.pdf
Node.js.pdfNode.js.pdf
Node.js.pdf
 
Quick introduction to nodeJs
Quick introduction to nodeJsQuick introduction to nodeJs
Quick introduction to nodeJs
 
Node on Windows Azure
Node on Windows AzureNode on Windows Azure
Node on Windows Azure
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 

More from Hüseyin BABAL (8)

Infinite Scalable Systems with Docker
Infinite Scalable Systems with DockerInfinite Scalable Systems with Docker
Infinite Scalable Systems with Docker
 
MongoDB GeoSpatial Feature
MongoDB GeoSpatial FeatureMongoDB GeoSpatial Feature
MongoDB GeoSpatial Feature
 
NodeJS ve API Tasarım Temelleri
NodeJS ve API Tasarım TemelleriNodeJS ve API Tasarım Temelleri
NodeJS ve API Tasarım Temelleri
 
RESTful API Design Fundamentals
RESTful API Design FundamentalsRESTful API Design Fundamentals
RESTful API Design Fundamentals
 
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJSToken Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJS
 
Token Based Authentication Systems
Token Based Authentication SystemsToken Based Authentication Systems
Token Based Authentication Systems
 
Make Your Application Social
Make Your Application SocialMake Your Application Social
Make Your Application Social
 
Realtime web applications with ExpressJS and SocketIO
Realtime web applications with ExpressJS and SocketIORealtime web applications with ExpressJS and SocketIO
Realtime web applications with ExpressJS and SocketIO
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

Complete MVC on NodeJS