I'm trying to return a search result. For this to work properly I understand I need a promise. When Googling this I get crazy different approaches. I'm looking for the most simple way.
This is my current script but it seems to be promised something but it does not get delivered, it keeps waiting.
var http = require('http');
var marklogic = require("marklogic");
var Promise = require('promise');
// File containing MarkLogic sever connection settings
var conn = require("./nodeMLserverSettings.js").connection;
// Start connection with database
var db = marklogic.createDatabaseClient(conn);
// Build a query in variable q
var q = marklogic.queryBuilder;
// Test MarkLogic NodeJS API
// console.dir(marklogic);
function promisedText(query, q, db) {
return new Promise(function (fulfill, reject){
db.documents.query(q.where(q.parsedFrom(query))).result().done(function (res){
try {
fulfill(JSON.parse(res));
} catch (ex) {
reject(ex);
}
}, reject);
});
}
promisedText('Consulting', q, db);
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');