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
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
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
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
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”
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