Ask coding questions

← Back to all posts
File getting erased
EnderInvader (0)

I have a file in node.js which I am writting a large json string to for storage of settings. This used to ork completely fine, but for some reason now when it writes to the file, the data shows up and then is quickly erased by another cursor.

Comments
hotnewtop
Coder100 (18934)

you must use fs.writeFileSync or the equivalent in your code.
Not sure why, but it has always worked for me.

Anyways, if you want to use a more reliable db, try replit database

InvisibleOne (3227)

I'm assuming that you are using fs?
I ran into that problem, since you need to use async functions when writing to the file, you can read from it without an async but writing returns a promise... or it might be the other way around.

EnderInvader (0)

@InvisibleOne I'm actually not using fs, although I have seen the same problem when using fs. Here I'm using StormDB, which runs synchronously.

InvisibleOne (3227)

Hmm, then I'm not sure what the problem is. @EnderInvader