简体   繁体   English

如何将 append 数据写入 javascript 中的 txt?

[英]How to append data to txt in javascript?

I'm writing a program, which needs to take some JSON from text file, then modify it and put it back to the same file, something like overwriting.我正在编写一个程序,它需要从文本文件中获取一些 JSON,然后对其进行修改并将其放回同一个文件,例如覆盖。 I don't have problem with reading from file and modifying data, but I was searching long and found nothing about writing into files.我从文件读取和修改数据没有问题,但是我搜索了很长时间,但没有发现任何关于写入文件的信息。 If it's important - it's server-side file.如果它很重要 - 它是服务器端文件。

Ex.前任。 text file: {"name":"John","age":20}文本文件: {"name":"John","age":20}
Result which I need: {"name":"John","age":21}我需要的结果: {"name":"John","age":21}

You can use the fs module in node to write to a file!您可以使用节点中的fs模块写入文件!

information is located here on it https://www.w3schools.com/nodejs/nodejs_filesystem.asp信息位于此处https://www.w3schools.com/nodejs/nodejs_filesystem.asp

The two methods you will want to look at is .writeFile or .appendFile depending on your specific need.您将要查看的两种方法是.writeFile.appendFile ,具体取决于您的具体需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM