Las versiones y el codigo que estoy usando es el siguiente:
node version v0.12.3000
express 3.20.3
app.js
Código Javascript:
Ver original
/** * Module dependencies. */ var express = require('express'); var routes = require('./routes'); var http = require('http'); var path = require('path'); var app = express(); var v_login = require('./routes/login'); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.logger('dev')); app.use(express.json()); app.use(express.urlencoded()); //app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); // development only if ('development' == app.get('env')) { app.use(express.errorHandler()); } app.get('/', routes.index); app.get('/login', v_login.login); app.get('/login', v_login.get_enviar); app.post('/login', v_login.post_enviar); http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); });
login.js
Código Javascript:
Ver original
var lista = new Array(); function login(req, res){ res.render('login'); lista: lista }; exports.login = login; exports.get_enviar = function(req, res){ login(req, res); } exports.post_enviar = function(req, res){ var usuario = req.body.usuario; var password = req.body.password; lista.push({ usuario: usuario, password: password }) console.log("usuario==>"+lista[0].usuario); console.log("password==>"+lista[0].password); login(req, res); }
login.jade
Código Javascript:
Ver original
doctype html html(lang='en') body #container form#frm(method="post", name="frm", action="login", enctype="application/x-www-form-urlencoded") h1 Login h2 usuario input#usuario(name='usuario', type='text', value='') br h2 password input#password(type='password', name='password', value='') input#chkpassword(type='checkbox', name='chkpassword') br br input(type='submit', value='Conectar') a(href='home') >> br br lista[0].usuario #mensaje #footer