I'm trying to do a function with JS and nodejs to create a .json file with my MongoDB data in it.
But when I run my function my console show me
Uncaught TypeError: Cannot read property 'prototype' of undefined.
I've done some research and my console that writeJsonFile's value is an object with no value, I don't know if it's the cause of my problem
json(event){
count = Subs.find({}).count();
var json;
var obj;
Subs.find({}).forEach(function (div) {
var sub_type = div.type;
var sub_TO = div.text;
var man = div.topic;
obj = {[man]: []};
obj[man].push({"type": sub_type, "TO": sub_TO});
json = JSON.stringify(obj);
const writeJsonFile = require('write-json-file');
writeJsonFile('foo.json', {foo: true}).then(() => {
console.log('done');
});
console.log(json);
});
}
writeJsonFilefunction whose code you don't show ?const writeJsonFile = require('write-json-file');and if i remove the code above i still have the problemwrite-json-filea third party module, or something you've written in the same folder as that JS code?write-json-fileis a npm install module that i found here [link] (github.com/sindresorhus/…)