I need to add two strings in an js file I am generating with writeFileSync
This is the code example
const svgs = [];
var n = 2;
for (var i = 0; i < n; i++) {
svgs.push(Cog.prototype.render());
svgs.push(Manna.prototype.render());
}
fs.writeFileSync(`client/data/${name}.json`, JSON.stringify(svgs));
And this is the js file I am generating ( two objects in an array )
[{"xmlns":"http://www.w3.org/svg/2000","viewBox":{"viewBox":"0 0 64 64"},"width":{"size":64},"height":{"size":64},"fill":{"fill":"currentcolor"},"path":{"d":{"pathData":"M 2 2 L 62 2 L 62 62 L 2 62 L 2 2"}}},{"xmlns":"http://www.w3.org/svg/2000","viewBox":{"viewBox":"0 0 64 64"},"width":{"size":64},"height":{"size":64},"fill":{"fill":"currentcolor"},"path":{"d":{"pathData":"M 2 2 L 62 2 L 62 62 L 2 62 L 2 2"}}}]
My question is how can I add two strings, this one at the beginning const svgs = and export default svgs at the end in order to make my file generated looking like this
const svgs = [{"xmlns":"http://www.w3.org/svg/2000","viewBox":{"viewBox":"0 0 64 64"},"width":{"size":64},"height":{"size":64},"fill":{"fill":"currentcolor"},"path":{"d":{"pathData":"M 2 2 L 62 2 L 62 62 L 2 62 L 2 2"}}},{"xmlns":"http://www.w3.org/svg/2000","viewBox":{"viewBox":"0 0 64 64"},"width":{"size":64},"height":{"size":64},"fill":{"fill":"currentcolor"},"path":{"d":{"pathData":"M 2 2 L 62 2 L 62 62 L 2 62 L 2 2"}}}] export default svgs;
fs.writeFileSync(client/data/${name}.json, "const svgs =" + JSON.stringify(svgs)) + "export default svgs" ;