estoy usando express con jade. Estoy tratando de hacer un factorial con una entrada, pero no puedo visualizar la respuesta por ejemplo si había entrada 5 el resultado es 120, pero mostrar un error grande. ¿Cómo puedo hacer esto? ¿Por favor me puedes ayudar?
views/factorial
extends layout
block content
h1= title
p Welcome to #{title}
p Ingrese un numero
form(method="POST", action="/factorial", name="myForm",onsubmit='return validateForm()')
input(type='number', name='numero')
input(type='submit', value='Enviar')
archive app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
//agregado
var bodyParser = require('body-parser');
var engine = require('ejs-mate');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// instruct the app to use the `bodyParser()` middleware for all routes
app.use(bodyParser());
// view engine setup
app.engine('ejs', engine);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'bower_components')));
app.use('/', routes);
app.use('/users', users);
app.post('/factorial', function(req, res) {
var num=req.body.numero;
dd(num);
for(var i=1;i<=num;i++)
i=i*num;
res.send('/factorial'+i);
});
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
routes/index.js
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index.jade', { title: 'Express' });
});
router.get('/factorial', function(req, res, next) {
res.render('factorial.jade', { title: 'Factorial' });
});
module.exports = router;