I have the following Node JS code running fine. However, I can't get the value of fullname
passed to the view. I can see the value in console.log
, but don't know why it is not being passed to the JADE file.
var express = require('express');
var router = express.Router();
var mongo = require('mongodb');
var fullname;
/* GET home page. */
router.post('/', function (req, res, next) {
select(function (data) {
fullname = data.name;
console.log(data.name);
});
var username = req.body.username;
var password = req.body.password;
res.render('myPage', {username: username, password: password, fullname: fullname});
});
function select(callback) {
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/mydb";
MongoClient.connect(url, function (err, db) {
if (err) throw err;
// Select record
db.collection("customers").findOne({}, function (err, result) {
if (err) throw err;
console.log(result.name);
callback(result);
});
});
}
via PHPDev
No comments:
Post a Comment