如何在Node.js中附加到新行 [英] How to append to New Line in Node.js

查看:116
本文介绍了如何在Node.js中附加到新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Node.js将数据附加到日志文件,并且工作正常,但它不会转到下一行。 \ n 似乎没有在我的函数下面工作。有什么建议吗?

I'm trying to Append data to a Log file using Node.js and that is working fine but it is not going to the next line. \n doesn't seem to be working in my function below. Any suggestions?

function processInput ( text ) 
{     
  fs.open('H://log.txt', 'a', 666, function( e, id ) {
   fs.write( id, text + "\n", null, 'utf8', function(){
    fs.close(id, function(){
     console.log('file is updated');
    });
   });
  });
 }


推荐答案

看起来你好像是在Windows上运行此命令(给定 H://log.txt 文件路径)。

It looks like you're running this on Windows (given your H://log.txt file path).

尝试使用 \\\\ n 而不是 \ n

老实说, \ n 没问题;您可能正在查看记事本中的日志文件或其他不呈现非Windows换行符的日志文件。尝试在不同的查看器/编辑器(例如写字板)中打开它。

Honestly, \n is fine; you're probably viewing the log file in notepad or something else that doesn't render non-Windows newlines. Try opening it in a different viewer/editor (e.g. Wordpad).

这篇关于如何在Node.js中附加到新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆