var url = require('url');
var pug = require('pug');
var PouchDB = require('pouchdb');
var db = new PouchDB('http://127.0.0.1:5984/data');
var doc = {
"_id": "mittens",
"name": "Mittens",
};
function query() {db.get('mittens', function (error, doc) {
if (error) {
console.log('Ops! There is an error.');
} else {
console.log(doc);
return doc;
}
});
}
module.exports = {
handleRequests: function(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
var path = url.parse(request.url).pathname;
console.log(path);
switch (path) {
case '/':
response.write(pug.renderFile('./views/index.pug', query()));
response.end();
break;
The query() function is returning an Object with "name". But it isn't rendered by pug.js.
Why pug.js do not render the Template with doc.name?