O
O
ojiekcahdp2021-02-03 23:56:27
Node.js
ojiekcahdp, 2021-02-03 23:56:27

How to overwrite a file?

There is a json file. You need to completely replace its contents with [].
How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-02-04
@ojiekcahdp

const fs = require('fs');
fs.writeFile('./my.json', '[]', error => console.log("Done!"));

A
Alexander, 2021-02-04
@Alexandre888

for (let key in json) delete json[key]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question