on my server side (nodejs), I have a file that calls a function (ldapjs) in another file but the returned value is undefined. The true value of client.bind is then displayed but it is not returned to the first file.
test2.js
const f = require('./ldap3');
console.log(f.ldap_conn());
ldap3.js
var ldap = require('ldapjs');
var client = ldap.createClient({url: 'ldap://ldap-pr.tsl.bobo.com:389'});
const dn = 'uid=myname,ou=people, ou=teamMembers,ou=internal,o=bobo'
const password = 'mypassword'
function ldap_conn(){
client.bind(dn, password, function(error){
if(error){
console.log('fail')
return('not ok')
}
else{
console.log('not fail')
return('ok')
}
})
}
//ldap_conn()
//console.log(test)
module.exports = {ldap_conn};
Result of test.js
undefined
not fail
test2.js should receive “ok” but it receives “undefined”.
But console.log(‘not fail’) works afterwards and this value is not returned.
In short, client.bind work fine but the value is not returned.