Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Contenido
Tipos de aplicaciones web
NodeJS
Express
EJS
Patrones habituales
TIPOS DE
APLICACIONES WEB
SPA / PAGE-REDRAW
TIPOS DE
APLICACIONES WEB
SPA
(single-page)
PAGE-REDRAW
(multi-page)
TIPOS DE
APLICACIONES WEB
PAGE-REDRAW
Enfoque clsico del desarrollo web: el cliente
solicita pginas y el servidor las construye.
TIPOS DE
APLICACIONES WEB
PAGE-REDRAW
GET
HTML
CLIENTE
h
s
e
r
ef
R
form POST
HTML
SERVIDOR
TIPOS DE
APLICACIONES WEB
PAGE-REDRAW
GET
HTML
CLIENTE
SERVIDOR
Ajax POST
TIPOS DE
APLICACIONES WEB
PAGE-REDRAW
GET
HTML
CLIENTE
h
s
e
r
ef
R
GET
HTML
SERVIDOR
TIPOS DE
APLICACIONES WEB
TIPOS DE
APLICACIONES WEB
CLIENTE
Refresh
NEVER
GET/POST/PUT
JSON
SERVIDOR
TIPOS DE
APLICACIONES WEB
PARA HOY:
PAGE-REDRAW
NODE JS
JAVASCRIPT EN EL SERVIDOR
NODE JS
Javascript en el servidor
Javascript autnomo
Single-Thread
NODE JS
NODE JS
Ejecucin normal
NODE JS
Ejecucin en cluster
NODE JS
Hello world
Servidor bsico con NodeJS
$ curl localhost:3000
Hello world
EXPRESS
HTTP PARA SERES HUMANOS
EXPRESS
Qu es?
Framework web para NodeJS
Inspirado en Sinatra
Dependiente de Connect
Express 4.0+
no depender
de Connect
EXPRESS
Popularidad
EXPRESS
En el mundo real
MySpace
LearnBoost
Persona (Mozilla)
Cozy
Apiary.io
EXPRESS
Hello world
Servidor bsico con Express
var express = require('express');
var http = require('http');
var app = express();
!
app.get('/', function (req, res) {
res.send(Hello world);
});
!
http.createServer(app).listen(3000);
$ curl localhost:3000
Hello world
EXPRESS
Servir archivos estticos
app.js
public/hello.txt
EXPRESS
Body
EXPRESS
Body
HTTP 200
Content-Length
Content-Type:
JSON
EXPRESS
Query
EXPRESS
Params
EJS
HTML PROGRAMADO
EXPRESS
Qu es?
Sistema de plantillas HTML
En cliente y en servidor
EJS
Hello world
!
app.get('/', function (req, res) {
res.render('index', {
title: Hello',
text: world'
});
});
!
http.createServer(app).listen(3000);
app.js
<h1>
<%= title %>
</h1>
<p>
<%= text %>
</p>
views/index.ejs
$ curl localhost:
3000
<h1>Hello</h1>
<p>world</p>
bash
EJS
<%= %>
app.js
<h1>
<%= title %>
</h1>
views/index.ejs
$ curl http://localhost:3000
!
<h1>hello</h1>
bash
EJS
<%= %>
app.js
<h1>
<%= title %>
</h1>
views/index.ejs
$ curl http://localhost:3000
!
<h1>a < b</h1>
bash
EJS
<%- %>
app.js
<h1>
<%- title %>
</h1>
views/index.ejs
$ curl http://localhost:3000
!
<h1>a < b</h1>
bash
EJS
<% %>
app.js
<h1>
<% title %>
</h1>
views/index.ejs
$ curl http://localhost:3000
!
<h1></h1>
bash
EJS
<% %>
views/index.ejs
app.js
$ curl http://localhost:3000
!
a < b
bash
EJS
<% %>
app.js
<% var a = 2; %>
hello <%- a %>
$ curl http://localhost:3000
!
hello 2
views/index.ejs
bash
ASPECTOS AVANZADOS
PATRONES HABITUALES
PATRONES HABITUALES
Control de acceso
Disposicin de rutas
Modelo compartido
PATRONES HABITUALES
Control de acceso (con clave)
PATRONES HABITUALES
Control de acceso (con sesiones)
PATRONES HABITUALES
Disposicin de rutas
app.js
routes/
sample.js
PATRONES HABITUALES
Esquema de una aplicacin
Estticos
Rutas
Vistas
PATRONES HABITUALES
Modelo compartido
model/Persona.js
PATRONES HABITUALES
Modelo compartido
app.js
PATRONES HABITUALES
Modelo compartido
public/model.html
GRACIAS
POR SU ATENCIN