Trying to write to a file

I am trying to write the the file bets.txt but it is giving me a access error.

The project folder isn’t at the root directory in the file system. Try removing the leading slash /.

fs.writeFileSync('bets.txt', ...
1 Like

I think that helped turns out I had to type refresh in the console to get the things to show up. Is their a way to refresh automatically

Please do not tell me you are trying to use a txt file as a database?

I guess you could say that I am, is there a better type of file for that.

This may be of interest to you.

1 Like

As a file format, I would recommend storing the data using SQLite. Then you can accept POST requests from the browser to mutate the data fairly easily and you can generate .json data from the .db file and send it to the browser when the browser GETs the data. That’s how ~hello-sqlite works.

Neither .txt nor .json is really intended to be used as a file format for a database - they are intended to be human-readable and human-editable with general text editors, which makes the libraries that treat them as if they were databases (libraries like lowdb or csv) more difficult to write, and often that shows up as either bugs or slugs in those libraries.

My advice is: follow along with ~hello-sqlite - it’s very close to what you want to build!