Top Banner
From Simple to Complex Powering websites, APIs and isomorphic web applications Alexandra Anghel, CTO Appticles.com
54
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Node.js, From Simple to Complex

From Simple to ComplexPowering websites, APIs and isomorphic web applications

Alexandra Anghel, CTO Appticles.com

Page 2: Node.js, From Simple to Complex

• V8 JavaScript engine

• Procesare asincrona, mai eficienta

vs. “un thread per request”

intro

Page 3: Node.js, From Simple to Complex

I

Cum facem un website cu NodeJS?

Page 4: Node.js, From Simple to Complex

I

Page 5: Node.js, From Simple to Complex

I

Page 6: Node.js, From Simple to Complex

• Fara baza de date & autentificare

• Mecanism pentru rutare

• Jade, Handlebars, Hogan, etc.

• V4+: fara middleware in afara de express:static

I

Page 7: Node.js, From Simple to Complex

middleware

routing

dev/production

I

Page 8: Node.js, From Simple to Complex

Template-ul principal: views/layout.jadeI

Page 9: Node.js, From Simple to Complex

I Cum facem un formular de contact?

Page 10: Node.js, From Simple to Complex

I

Template-ul formularului: views/contact.jade (1)

Page 11: Node.js, From Simple to Complex

I

Template-ul formularului: views/contact.jade (2)

Page 12: Node.js, From Simple to Complex

I Ruta ce incarca formularul: routes/index.js

Page 13: Node.js, From Simple to Complex

I

$ npm install nodemailer

app.js

Page 14: Node.js, From Simple to Complex

I Trimite mesajul: routes/ajax.js (1)

Page 15: Node.js, From Simple to Complex

I

Trimite mesajul: routes/ajax.js (2)

Page 16: Node.js, From Simple to Complex

II

Cum facem un API cu NodeJS?

Page 17: Node.js, From Simple to Complex

• Verbe HTTP (GET, POST, PUT, DELETE)

II

• Conectarea cu o baza de date

• next()

• URL rewriting (api/users; api/user/:id)

Page 18: Node.js, From Simple to Complex

Mongoose: npm install mongoose

II

MongoSkin, Mongolia, Mongojs, MongoSmash

+

Page 19: Node.js, From Simple to Complex

IIStructura API-ului

Page 20: Node.js, From Simple to Complex

II

Conectarea la baza de date: app.js

Page 21: Node.js, From Simple to Complex

II

Modelul: models/user.js

Page 22: Node.js, From Simple to Complex

IIRute afisare si adaugare: routes/users.js (1)

Page 23: Node.js, From Simple to Complex

IIRute modificare si stergere: routes/users.js (2)

Page 24: Node.js, From Simple to Complex

Middleware pentru toate request-urile: routes/index.js

II

Page 25: Node.js, From Simple to Complex

Afisare lista de utilizatori: routes/users.js

II

Page 26: Node.js, From Simple to Complex

Adaugare utilizator: routes/users.js

II

Page 27: Node.js, From Simple to Complex

II Adaugare utilizator (POSTMAN)

Page 28: Node.js, From Simple to Complex

III

Aplicatii izomorfice

Page 29: Node.js, From Simple to Complex

III

Modelul clasic client/server

Client

(Browser)

Ruby

Python

Java

PHP

Server

request HTMLdate

Page 30: Node.js, From Simple to Complex

III

• SEO

• Viteza de incarcare / performanta

http://googlewebmastercentral.blogspot.ro/2014/05/understanding-web-pages-better.html

Aplicatii single-page - Probleme

Page 31: Node.js, From Simple to Complex

III

Client + Server (aplicatie izomorfica)

Client

(Browser)

Server

(Node JS)

Aplicatie sync

Page 32: Node.js, From Simple to Complex

III

Meteor is a complete open source

platform for building web and mobile

apps in pure JavaScript.

Page 33: Node.js, From Simple to Complex

III

• Template-uri

• Pachete

• Structura aplicatiei

• Baza de date

Page 34: Node.js, From Simple to Complex

III

meteor search [name]

meteor add [name]

meteor list

Propriul manager de pachete

Page 35: Node.js, From Simple to Complex

IIICautare pachete Meteor

Page 36: Node.js, From Simple to Complex

III

Page 37: Node.js, From Simple to Complex

III

Page 38: Node.js, From Simple to Complex

III Structura unei aplicatii

• /server

• /.meteor

• /client (templates, CSS)

• /public (imagini, alte fisiere statice)

• Fisiere comune server & client

Page 39: Node.js, From Simple to Complex

III

• Inclusions: insereaza un alt template

{{> nav}}

• Expressions

{{pageTitle}}

• Block helpers

#each, #if, #each, #with, #unless

Spacebars

Page 40: Node.js, From Simple to Complex

III

meteor

meteor mongo

+

Page 41: Node.js, From Simple to Complex

III

Client

• MiniMongo

• Subset al bazei de date reale

Server

• API pentru MongoDB

Page 42: Node.js, From Simple to Complex

III

Exemplu: Lista de comentarii

Titlu

Titlu

Titlu

Page 43: Node.js, From Simple to Complex

IIIView-ul principal: client/main.html

Page 44: Node.js, From Simple to Complex

III Template pentru lista de comentarii: client/comments/list.html

Template pentru un comentariu: client/comments/item.html

Page 45: Node.js, From Simple to Complex

III Afiseaza comentarii in lista: client/comments/list.js

Page 46: Node.js, From Simple to Complex

IIIAplicatia este actualizata in browser fara refresh

Page 47: Node.js, From Simple to Complex

III

Page 48: Node.js, From Simple to Complex

III

Legatura cu baza de date: lib/collections/comments.js

Page 49: Node.js, From Simple to Complex

III

Adauga element in baza de date din consola browserului

Page 50: Node.js, From Simple to Complex

III

Afiseaza comentarii adaugate din consola MongoDB

Page 51: Node.js, From Simple to Complex

III meteor remove insecure

meteor remove autopublish

Server, filtreaza comentarii afisate: server/publications.js

Client, legatura cu baza de date: client/main.js

Page 52: Node.js, From Simple to Complex

III

Client, afiseaza comentarii: client/comments/list.js

Page 53: Node.js, From Simple to Complex

III http://docs.meteor.com/#/full

Page 54: Node.js, From Simple to Complex

Multumesc!

Alexandra Anghel

[email protected]