首页 > 解决方案 > 如何在 fs 文本文件中进行换行以进行日志记录

问题描述

我正在使用 fs 模块来记录我的 node.js 应用程序,但我在谷歌上找不到如何使用 fs 对文本文件进行换行...

我已经尝试了一些 fs.append ,其中没有任何内容,但它什么也没做。

在此先感谢,〜待定

编辑:我正在使用 .txt 文件来启用快速日志读取...

标签: javascriptnode.jsfs

解决方案


如果有一些示例代码可以显示以获取更多帮助,那就太好了,但通常代码如下所示:

//Suggesting you are using ES6, if not, change all 'const' to 'var'

const fileSystem = require('fs');

//Change the data below, the path and data, but not the \n. There might be problems when using \n, if it occurs, consider changing it to \r.
fileSystem.writeFileSync('./path/to/your/file.txt', 'yourdata\n');

请参阅:\n 或 \r


推荐阅读