This document discusses API driven applications using the MEAN stack. It provides an overview of Node.js, explaining that it is a JavaScript runtime environment for server-side applications. It also introduces MongoDB, describing it as a NoSQL database that stores data in JSON-like documents rather than tables. The document then covers basic CRUD operations in MongoDB using Mongoose and building RESTful APIs with Express.js to interact with the MongoDB database from a Node.js backend.
Report
Share
Report
Share
1 of 28
Download to read offline
More Related Content
Getting started with node JS
1. API Driven Applications
AngularJS, NodeJS and MongoDB
@HmidiHamdi
Software Engeneering | ISSATSo
Member & Founder | ISSATSo Google Club
CXO | OMNIA
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).
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);
});
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);