如何在Node.js中附加到新行

时间:2012-04-30 13:15:56

标签: javascript node.js newline

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

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');
    });
   });
  });
 }

3 个答案:

答案 0 :(得分:130)

看起来你在Windows上运行它(给定H://log.txt文件路径)。

尝试使用\r\n而非\n

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

答案 1 :(得分:59)

改为使用os.EOL常量。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    [navigationBarAppearance setBarTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setTranslucent:NO];
    return YES;
}

答案 2 :(得分:3)

使用assert(evensquared(1)==1) assert(evensquared(2)==4) assert(evensquared(3)==27) assert(evensquared(4)==16) assert(evensquared(0)==0) 组合在节点js中添加新行

\r\n
相关问题