i am trying to generate a .js file by running a node script. here's my code.
const dynamicCode = [
{
"ClassCode" : "9620",
"Rate" : 0.99,
"IsActive" : "TRUE",
"StartDate" : "2021-10-19T17:00:00.000-07:00",
"EndDate" : "9999-12-30T16:00:00.000-08:00"
},
{
"ClassCode" : "0038",
"Rate" : 12.19,
"IsActive" : true,
"StartDate" : "2021-05-31T17:00:00.000-07:00",
"EndDate" : "9999-12-30T16:00:00.000-08:00"
}
]
const bdCode = module.exports = {
async up(db, client) {
await db.collection('Configuration_Lookup').deleteMany();
await db.collection('Configuration_Lookup').insertMany(dynamicCode)
},
async down(db, client) {
// TODO write the statements to rollback your migration (if possible)
// Example:
// await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});
}
};
fs.writeFileSync("bds.js", JSON.stringify(bdCode, null, 2), 'utf-8');
while this worked for .txt files containing simple texts, or non-executable codes like json objects. it is executing before running the writeFileSync function. so the data inserting into the js file is
{}
how can we generate a js file with working code inside it