'Export from JSON always return "Blob is not defined"
I want to create an excel file from my database, after that the file will be saved in the stored/client/ folder.
I use export-from-json
import exportFromJSON from "export-from-json";
import fs from "fs";
import path from "path";
import { Blob } from "buffer";
import db from "./dbConnect";
import Client from "../models/Clients";
function isRealValue(obj) {
return obj && obj !== "null" && obj !== "undefined";
}
async function exportData(client, time) {
const postsDirectory = path.join(process.cwd(), `stored/client/${client}`);
await db.dbConnect();
const result = await Client.findOne({ client: client }).lean();
await db.dbDisconnect();
const exportType = exportFromJSON.types.xls;
if (isRealValue(result)) {
fs.writeFile(
postsDirectory,
exportFromJSON({ data: result.message, fileName: client, exportType }),
function (err) {
if (err) throw err;
console.log("Results Received");
}
);
}
}
const dataFn = { exportData };
export default dataFn;
but the result always "Blob is not defined". I have tried to change into simple data like export-from-json
did and the result still the same.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|