0

I am getting the below error while connecting to LDAP using nodejs in GCP cloud function

Error: TypeError: options (object) required at Object.createClient

Index.js

exports.helloWorld = (event, context) => {
  const gcsEvent = event;
  var username = ***;
  var password = ***;
  console.log(`hello world`);
  var ldap = require('ldapjs');
  var client =ldap.createClient(username, password)({
   url: 'LDAP://...'
    }) 

client.bind(username, password,  function(error){
   if(error){ 
      console.log("error");
        } 
    else{ 
    console.log("Connected to ldap");
   } 
})
}

Package.json

{
  "name": "sample-http",
  "version": "0.0.1",
 "author": "sang",
  "description": "LDAP Binding for node.js",
   "dependencies": {
    "ldapjs": "^0.7.1"
  }
  }
Sang
  • 21
  • 1
  • 3

1 Answers1

0

var client =ldap.createClient(username, password)({ url: 'LDAP://...' })

shouldn't it be like

var client =ldap.createClient({ url: 'LDAP://...' })

createClient take Object as an argument while you are providing username and password..

Reference npmdoc

enter image description here

Himanshu Bansal
  • 2,003
  • 1
  • 23
  • 46