write/readFileSync Buffer & Data when stringifying

This is JSON + JavaScript Help Needed (not discord.js)

I’m slightly confused myself… here’s a link to my project: https://glitch.com/~skycade

I’m making a discord bot with discord.js and I’m trying to:
When player joins, create invite link, add the following information to list-invite.json (name of new player, newplayer’s id, time of joining, newplayer’s invite code).

Not only does the list-invite.json not add the info above ^^, but also when I try to “readFileSync” and stringify the file it shows “{“type”:“Buffer”,“data”:[91,123,34,68,97,116,101,34,58,34,49,49,47,49,57,47,50,48,49,57,32,55,58,50,57,58,52,57,34,44,34,78,97,109,101,34,58,34,84,105,103,101,114,114,114,114,114,35,53,56,55,49,34,44,34,73,100,34,58,34,50,57,48,52,56,53,55,52,57,49,51,48,55,50,51,51,50,56,34,44,34,67,111,100,101,34,58,34,75,103,78,69,50,68,86,34,125,93]}” rather than [{“Date”:“11/19/2019 6:31:51”,“Name”:“Tigerrrrr#5871”,“Id”:“290485749130723328”,“Code”:“NBeNyc7”}].

So in short, I’m trying to append a JavaScript object and write it into a file, then read the file, but it’s not returning the same object string as I appended in the first place.

Sorry if this is confusing but just comment below and I’ll reply whenever I can.

fs.readFileSync returns a Buffer if encoding is not specified.

Try something like this:

let obj = JSON.parse(fs.readFileSync('someFile.json', 'utf8'));


1 Like

just use a buffer.from()

This, worked. Thanks!

1 Like