Registered callback does not work out

I’m trying to write my first simple plugin for Obsidian. One of the parts of its functionality is to get some data from LDAP. For this I use the library
The search logic in it is implemented something like this:'o=example', opts, (err, res) => {

  res.on('searchRequest', (searchRequest) => {
    console.log('searchRequest: ', searchRequest.messageID);
  res.on('searchEntry', (entry) => {
    console.log('entry: ' + JSON.stringify(entry.object));
  res.on('searchReference', (referral) => {
    console.log('referral: ' + referral.uris.join());
  res.on('error', (err) => {
    console.error('error: ' + err.message);
  res.on('end', (result) => {
    console.log('status: ' + result.status);

that is, a callback function is registered for each type of event. My problem is that the callbacks for searchRequest and end work fine while the rest just don’t work. Exactly the same logic on the same laptop running outside of Obsidian works as expected.

I’m not asking for help with LDAP or this library. I ask you to tell me what I’m missing with the logic of processing callbacks in Obsidian. The difficulty is that the JavaScript ecosystem is almost completely unfamiliar to me.