Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:04:53+00:00 2026-06-06T15:04:53+00:00

With Node I am trying to collect user data from an LDAP server and

  • 0

With Node I am trying to collect user data from an LDAP server and then write that data to a JSON file. I am using the following code to do this:

fs.writeFile('data.json', JSON.stringify(data, null, 4));

The problem is the JSON.stringify method is causing the following error:

FATAL ERROR: JS Allocation failed - process out of memory

I know the problem is with JSON.stringify because if I use console.log rather than fs.writeFile I get the same error.

I am trying to write a lot of data (over 500 entries in the LDAP database). Does anyone know how I can get this to work? Here is the code in full:

var ldap = require('ldapjs');
var util = require('util');
var fs = require('fs');
var client = ldap.createClient({
  url: '************'
});

client.bind('CN=**********,OU=Users,OU=LBi UK,OU=UK,DC=********,DC=local', '*********', function(err) {
  if (err) {
    console.log(err.name);
  }
});


// taken from http://ldapjs.org/client.html
client.search('OU=Users,OU=******,OU=UK,DC=******,DC=local', {
  scope: 'sub',
  filter: 'objectClass=organizationalPerson',
  attributes: ['givenName', 'dn', 'sn', 'title', 'department', 'thumbnailPhoto', 'manager']
  // filter by organizational person
}, function(err, res) {
  if (err) {
    console.log(err.name);
  }

  var limit = 1;
  var data = {"directory": []};

  res.on('searchEntry', function(entry) {

    var obj = {};
    entry.attributes.forEach(function (attribute) {
      var value;
      if (attribute.type === 'thumbnailPhoto') {
        value = attribute.buffers[0];

      } else {
        value = attribute.vals[0];
      }
      obj[attribute.type] = value;
    });
    data.directory.push(obj);
  });
  res.on('error', function(err) {
    console.log('error: ' + err.message);
  });
  res.on('end', function(result) {
    fs.writeFile('data.json', JSON.stringify(data, null, 4));
  });

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:04:55+00:00Added an answer on June 6, 2026 at 3:04 pm

    As @freakish mentioned the problem was my data was too big.

    The reason the data was so big was due to a large number of images that were being returned as objects. In the end all I needed to do was encode the object as base64 using Buffers and then the size of the data became much more manageable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to pull out a node from a csproj file that looks like
I'm trying to use Node.js to create a zip file from an existing folder,
I'm trying to user node-proxy to auto-magically read/write databases and I can't figure a
Im trying to delete a node in XML file using Javascript. The used browser
I'm using Node.js and trying to render an EJS template file. I figured out
I am messing around in Node.js trying to replicate that simple chat server that
I am using node.js and trying send the .html file contains these tags: <meta
I'm trying to insert an element node (that has some children) from one XML
Playing and trying to see how fast node.js can serve a static file from
I am trying to update a child node of an XML file IE Changing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.