SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
API Driven Applications
AngularJS, NodeJS and MongoDB
@HmidiHamdi
Software Engeneering | ISSATSo
Member & Founder | ISSATSo Google Club
CXO | OMNIA
Agenda
- API Driven Application
- Basics Of Node JS
- Discovering MongoDB
API DRIVEN APPLICATION
REST API
REST = Representation State Transfer.
- Client Sends HTTP verbs(GET, POST,
DELETE, PUT) along with a URL and
variable parameters that are unlencoded.
- The URL tells us what object to act on.
- Server Replies with a result code and valid
JSON.
HTTP Verbs - CRUD
- GET : when a client want to read an object.
- POST : when a client want to ceate an
object.
- PUT : when a client want to update an
object.
- DELETE : when a client want to delete an
object.
Why REST API ?
a simple way to create a data service enabling
you to easy create all your other applications:
- HTML5 / JAVASCRIPT.
- ANDROID.
- IOS.
MEAN STACK
M : MongoDB (Most Popular NoSql DataBase).
E : ExpressJS (Web Application Framework).
A : AngularJS (A Robust Framework for
creating HTML5 and Javascript rich web
Applications).
N : NodeJS (Server-side Javascript interpreter).
What is NodeJS ?
● Open Source, Cross-platform runtime
environment for server-side and networking
applications.
● NodeJS provides an Event-Driven
architecture and non-blocking I/O API.
● Run your Javascript on Server.
● Uses V8 Engine.
Getting Started with Nodejs
- Install / Build Nodejs
- Type your Script
- open Terminal and run script using :
“node filename.js”
What can you do with NodeJS
- You can create an HTTP server and print ‘hello world’ on the browser in
just 4 lines of JavaScript.
- You can create a DNS server.
- You can create a Static File Server.
- You can create a Web Chat Application like GTalk in the browser.
- Node.js can also be used for creating online games, collaboration tools or
anything which sends updates to the user in real-time.
Hello Node JS
//On inclus la librairie http qui permet la création d'un serveur http basique
var http = require('http');
http.createServer( function (request, response) {
//Le type de contenu sera HTML, le code de réponse 200 (page correctement chargée)
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('Hello <a href="http://www.google.com.fr”>World</a> :pn');
} ).listen(666);
//On affiche un petit message dans la console histoire d'être sûr que le serveur est lancé
console.log('Visit http://localhost:666 ');
Node Package Manager
Express JS
Uses
app.use(express.static(__dirname + '/Public'));
// set the static files location /public/img will be /img for users
app.use(morgan('dev'));
// log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.json());
// parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
// parse application/vnd.api+json as json
app.use(methodOverride());
Routes
app.get('/todos/:id', function (req, res, next) {
var todo=getTodo(id);
res.json(todo);
});
-------------
app.get('/todos', function (req, res, next) {
var todos= getTodos();
res.json(todos);
});
What is MongoDB?
MongoDB is an Open-Source document-
oriented NoSQL database. It stores data in
JSON-like format.
Why use MongoDB ?
- SQL databases was invented to store data.
- MongoDB stores documents (or) Objects.
- now-a-days, everyone works with Objects
(Python/Ruby/Java/etc).
- And we need Databases to persist our objects.
- why not store objects directly?
- Embedded documents and arrays reduce need for Join.
MongoDB Tools
● Mongo : MongoDB client as a Javascript
shell.
● MongoImport : import CSV, JSON and TSV
data.
● MongoExport : export data as JSON and
CSV.
NoSQL DataBase Terms:
DataBase : Like other Relational DataBases.
Collection : Like Table in RDBMS(Has no
common Schema).
Document : Like a Record in RDBMS or Row.
Field : Like a RDBMS column {key : value }.
Mongoose CRUD(Create, Read, Update,
Delete)
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/MyApp');
var SpeakerSchema = new mongoose.Schema({
name : String ,
img : String,
detail : String
});
var Speaker = mongoose.model('Speaker',SpeakerSchema);
Create
app.post('/NewSpeaker',function(req,res){
var sp = new Speaker({
name : req.body.nameS,
img : req.body.imgS,
detail: req.body.det
});
sp.save(function(err){
if(err)
console.log(err);
else
res.json(sp);
});
});
Read
app.get('/getSpeakers/:Name',function(req,res){
Speaker.findOne({ name: req.params.Name }, function (err, doc){
if (err){
res.send(err);
}
res.json(doc);
});
});
app.get('/getSpeakers',function(req,res){
Speaker.find(function(err, todos) {
if (err){
res.send(err);
}
res.json(todos); // return all todos in JSON format
});
});
Update
● Model.update(conditions, update, [options],
[callback])
Delete
● Model.remove(conditions, [callback])
app.delete('/DeleteSpeaker/:id',function(req,res){
Speaker.remove({ _id : req.params.id}, function (err) {
if (err) return res.send(err);
res.json({"result":"success"});
});
});
<Coding Time !>
<Thank You!>
Hmidihamdi7@gmail.com
/+ HamdiHmidiigcien
/hamdi.igc

Weitere ähnliche Inhalte

Was ist angesagt?

Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core Data
Inferis
 

Was ist angesagt? (20)

3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Node js getting started
Node js getting startedNode js getting started
Node js getting started
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Analyse Yourself
Analyse YourselfAnalyse Yourself
Analyse Yourself
 
Rest api with node js and express
Rest api with node js and expressRest api with node js and express
Rest api with node js and express
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsThe MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
 
Getting started with node.js
Getting started with node.jsGetting started with node.js
Getting started with node.js
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJS
 
Web Development with AngularJS, NodeJS and ExpressJS
Web Development with AngularJS, NodeJS and ExpressJSWeb Development with AngularJS, NodeJS and ExpressJS
Web Development with AngularJS, NodeJS and ExpressJS
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...
 
Introduction about-ajax-framework
Introduction about-ajax-frameworkIntroduction about-ajax-framework
Introduction about-ajax-framework
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePoint
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
 
Nodejs vs php_apache
Nodejs vs php_apacheNodejs vs php_apache
Nodejs vs php_apache
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core Data
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 

Andere mochten auch

Alla scoperta di Marte
Alla scoperta di MarteAlla scoperta di Marte
Alla scoperta di Marte
chreact
 
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
lashkova
 
бойко вера. работа со спонсорами, превосходя все ожидания
бойко вера. работа со спонсорами, превосходя все ожиданиябойко вера. работа со спонсорами, превосходя все ожидания
бойко вера. работа со спонсорами, превосходя все ожидания
lashkova
 
шинкаревская
шинкаревскаяшинкаревская
шинкаревская
lashkova
 
CharityVillageAssessmentReport
CharityVillageAssessmentReportCharityVillageAssessmentReport
CharityVillageAssessmentReport
Digital Systems
 
Resume and cover letter of Muhammad Mollah
Resume and cover letter of Muhammad MollahResume and cover letter of Muhammad Mollah
Resume and cover letter of Muhammad Mollah
Digital Systems
 

Andere mochten auch (20)

Alla scoperta di Marte
Alla scoperta di MarteAlla scoperta di Marte
Alla scoperta di Marte
 
Veggie market rei
Veggie market reiVeggie market rei
Veggie market rei
 
Mars-Rover
Mars-RoverMars-Rover
Mars-Rover
 
THE FRUIT
THE FRUITTHE FRUIT
THE FRUIT
 
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
Евгений Собин, Что необходимо знать при организации детского КВН… и любого де...
 
THE FRUITS
THE FRUITSTHE FRUITS
THE FRUITS
 
Joomla! based website redesign project by Digital Systems
Joomla! based website redesign project by Digital SystemsJoomla! based website redesign project by Digital Systems
Joomla! based website redesign project by Digital Systems
 
бойко вера. работа со спонсорами, превосходя все ожидания
бойко вера. работа со спонсорами, превосходя все ожиданиябойко вера. работа со спонсорами, превосходя все ожидания
бойко вера. работа со спонсорами, превосходя все ожидания
 
шинкаревская
шинкаревскаяшинкаревская
шинкаревская
 
Ng-init
Ng-init Ng-init
Ng-init
 
The color of green energy
The color of green energyThe color of green energy
The color of green energy
 
Cosa ci dicono le particelle "strane"?
Cosa ci dicono le particelle "strane"?Cosa ci dicono le particelle "strane"?
Cosa ci dicono le particelle "strane"?
 
Ng-init
Ng-init Ng-init
Ng-init
 
CharityVillageAssessmentReport
CharityVillageAssessmentReportCharityVillageAssessmentReport
CharityVillageAssessmentReport
 
Resume and cover letter of Muhammad Mollah
Resume and cover letter of Muhammad MollahResume and cover letter of Muhammad Mollah
Resume and cover letter of Muhammad Mollah
 
l calore del colore
l calore del colore l calore del colore
l calore del colore
 
Pericoli dallo spazio
Pericoli dallo spazioPericoli dallo spazio
Pericoli dallo spazio
 
Twitter bootstrap | JCertif Tunisie
Twitter bootstrap | JCertif Tunisie Twitter bootstrap | JCertif Tunisie
Twitter bootstrap | JCertif Tunisie
 
Brand promotion strategy for Sellers - Lamido VN
Brand promotion strategy for Sellers - Lamido VNBrand promotion strategy for Sellers - Lamido VN
Brand promotion strategy for Sellers - Lamido VN
 
Ng init
Ng initNg init
Ng init
 

Ähnlich wie Getting started with node JS

An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
Ayush Mishra
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 

Ähnlich wie Getting started with node JS (20)

An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
node js.pptx
node js.pptxnode js.pptx
node js.pptx
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Node.js
Node.jsNode.js
Node.js
 
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
API  Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015 API  Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Nodejs
NodejsNodejs
Nodejs
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Proposal
ProposalProposal
Proposal
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
 
Nodejs
NodejsNodejs
Nodejs
 

Mehr von Hamdi Hmidi (7)

Pentaho | Data Integration & Report designer
Pentaho | Data Integration & Report designerPentaho | Data Integration & Report designer
Pentaho | Data Integration & Report designer
 
Javascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITComJavascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITCom
 
Modern web application devlopment workflow
Modern web application devlopment workflowModern web application devlopment workflow
Modern web application devlopment workflow
 
Les Basiques - Web Développement HTML5, CSS3, JS et PHP
Les Basiques - Web  Développement HTML5, CSS3, JS et PHPLes Basiques - Web  Développement HTML5, CSS3, JS et PHP
Les Basiques - Web Développement HTML5, CSS3, JS et PHP
 
Hybrid Mobile Apps | Ionic & AngularJS
Hybrid Mobile Apps | Ionic & AngularJSHybrid Mobile Apps | Ionic & AngularJS
Hybrid Mobile Apps | Ionic & AngularJS
 
Android initiation
Android initiationAndroid initiation
Android initiation
 
Les Fondamentaux D'Angular JS | Hmidi Hamdi
Les Fondamentaux D'Angular JS | Hmidi HamdiLes Fondamentaux D'Angular JS | Hmidi Hamdi
Les Fondamentaux D'Angular JS | Hmidi Hamdi
 

Kürzlich hochgeladen

一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
Asmae Rabhi
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
galaxypingy
 

Kürzlich hochgeladen (20)

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
 

Getting started with node JS

  • 1. API Driven Applications AngularJS, NodeJS and MongoDB @HmidiHamdi Software Engeneering | ISSATSo Member & Founder | ISSATSo Google Club CXO | OMNIA
  • 2. Agenda - API Driven Application - Basics Of Node JS - Discovering MongoDB
  • 4. REST API REST = Representation State Transfer. - Client Sends HTTP verbs(GET, POST, DELETE, PUT) along with a URL and variable parameters that are unlencoded. - The URL tells us what object to act on. - Server Replies with a result code and valid JSON.
  • 5. HTTP Verbs - CRUD - GET : when a client want to read an object. - POST : when a client want to ceate an object. - PUT : when a client want to update an object. - DELETE : when a client want to delete an object.
  • 6. Why REST API ? a simple way to create a data service enabling you to easy create all your other applications: - HTML5 / JAVASCRIPT. - ANDROID. - IOS.
  • 7. MEAN STACK M : MongoDB (Most Popular NoSql DataBase). E : ExpressJS (Web Application Framework). A : AngularJS (A Robust Framework for creating HTML5 and Javascript rich web Applications). N : NodeJS (Server-side Javascript interpreter).
  • 8.
  • 9. What is NodeJS ? ● Open Source, Cross-platform runtime environment for server-side and networking applications. ● NodeJS provides an Event-Driven architecture and non-blocking I/O API. ● Run your Javascript on Server. ● Uses V8 Engine.
  • 10. Getting Started with Nodejs - Install / Build Nodejs - Type your Script - open Terminal and run script using : “node filename.js”
  • 11. What can you do with NodeJS - You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript. - You can create a DNS server. - You can create a Static File Server. - You can create a Web Chat Application like GTalk in the browser. - Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time.
  • 12. Hello Node JS //On inclus la librairie http qui permet la création d'un serveur http basique var http = require('http'); http.createServer( function (request, response) { //Le type de contenu sera HTML, le code de réponse 200 (page correctement chargée) response.writeHead(200, {'Content-Type': 'text/html'}); response.end('Hello <a href="http://www.google.com.fr”>World</a> :pn'); } ).listen(666); //On affiche un petit message dans la console histoire d'être sûr que le serveur est lancé console.log('Visit http://localhost:666 ');
  • 15. Uses app.use(express.static(__dirname + '/Public')); // set the static files location /public/img will be /img for users app.use(morgan('dev')); // log every request to the console app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded app.use(bodyParser.json()); // parse application/json app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json app.use(methodOverride());
  • 16. Routes app.get('/todos/:id', function (req, res, next) { var todo=getTodo(id); res.json(todo); }); ------------- app.get('/todos', function (req, res, next) { var todos= getTodos(); res.json(todos); });
  • 17.
  • 18. What is MongoDB? MongoDB is an Open-Source document- oriented NoSQL database. It stores data in JSON-like format.
  • 19. Why use MongoDB ? - SQL databases was invented to store data. - MongoDB stores documents (or) Objects. - now-a-days, everyone works with Objects (Python/Ruby/Java/etc). - And we need Databases to persist our objects. - why not store objects directly? - Embedded documents and arrays reduce need for Join.
  • 20. MongoDB Tools ● Mongo : MongoDB client as a Javascript shell. ● MongoImport : import CSV, JSON and TSV data. ● MongoExport : export data as JSON and CSV.
  • 21. NoSQL DataBase Terms: DataBase : Like other Relational DataBases. Collection : Like Table in RDBMS(Has no common Schema). Document : Like a Record in RDBMS or Row. Field : Like a RDBMS column {key : value }.
  • 22. Mongoose CRUD(Create, Read, Update, Delete) var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/MyApp'); var SpeakerSchema = new mongoose.Schema({ name : String , img : String, detail : String }); var Speaker = mongoose.model('Speaker',SpeakerSchema);
  • 23. Create app.post('/NewSpeaker',function(req,res){ var sp = new Speaker({ name : req.body.nameS, img : req.body.imgS, detail: req.body.det }); sp.save(function(err){ if(err) console.log(err); else res.json(sp); }); });
  • 24. Read app.get('/getSpeakers/:Name',function(req,res){ Speaker.findOne({ name: req.params.Name }, function (err, doc){ if (err){ res.send(err); } res.json(doc); }); }); app.get('/getSpeakers',function(req,res){ Speaker.find(function(err, todos) { if (err){ res.send(err); } res.json(todos); // return all todos in JSON format }); });
  • 26. Delete ● Model.remove(conditions, [callback]) app.delete('/DeleteSpeaker/:id',function(req,res){ Speaker.remove({ _id : req.params.id}, function (err) { if (err) return res.send(err); res.json({"result":"success"}); }); });