Q:

Cannot display data in a view in a express nodejs app

I'm brand new to express and node and I'm creating a simple express app that gets data stored in a json file,on my post/details view the data stored is not rendering.I believe is the way i pull the data from the json file but i can't see where is the error??
Here is the code:
posts.json
[
    {
        "name": "first name",
        "description": "test first description",
        "slug": "first-name",
        "id": "2f065d59"
    },
   {
        "name": "second name",
        "description": "test second description",
        "slug": "second-name",
        "id": "0071b034"
    }
]

postslist.js
var express = require('express');
var Creatordb = require('./database/posts.json');
var fs = require('fs');
var uuid = require('node-uuid');

var list = function () {
return Creatordb;
};

var getById = function (id) {
     for(var i=0;i<Creatordb.length;i++) {
         var id = Creatordb[i].id;
   }
return id;
};

exports.list = list;
exports.getById = getById;

post.js
var express = require('express');
var router = express.Router();
var db = require('./postslist');
var fs = require('fs');

exports.index = router.get('/',function (req, res) {
    res.render('post/index', { posts: db.list()});
});

exports.form = router.get('/create',function (req, res) {
    res.render('post/form');
});

exports.details = router.get('/details/:id',function (req, res, next) {
    console.log(req.body.name);
    console.log(req.body.description);
    console.log(req.body.id);
    //console log gives me this:
    undefined
    undefined
    undefined

    var post = db.getById(req.params.id);
    res.render('post/details', {post:post});
    });

module.exports = router;

app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var uuid = require('node-uuid');
var routes = require('./routes/index');
var post = require('./routes/post');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use('/', routes);
app.use('/post', post);

module.exports = app;

I can acess the post/details/:id route fine but the name description and other params don't display.
Can anyone explain to me what I'm missing here? - Thanks.

A:

Correct your getById function
    var getById = function (id) {
      for(var i=0;i<Creatordb.length;i++) {
        if(Creatordb[i].id == id){
          return Creatordb[i];
        }
      }
    };

