break line Node.js using Fs

Asked

Viewed 2,831 times

0

I need to print the variable result with line break in a txt file, I have the following code :

var Resultado = formatters.addTrailingZeros(req.query.Nrbanco, 3)        + 
    '0000'                                                              + 
    '0'                                                                 + 
    formatters.addEspacos(' ', 9)                                       + 
    formatters.addTrailingZeros(req.query.TipoInscricao, 1)             + 
    formatters.addTrailingZeros(req.query.IncricaoCedente, 15)          + 
    formatters.addTrailingZeros(req.query.Convenio, 20)                 + 
    formatters.addTrailingZeros(req.query.Agencia , 5)                  + 
    formatters.addTrailingZeros(req.query.AgenciaDigito , 1)            + 
    formatters.addTrailingZeros(req.query.Conta , 12)                   + 
    formatters.addTrailingZeros(req.query.ContaDigito , 1)              + 
    ' '                                                                 + 
    formatters.addTrailingZeros(req.query.Cedente , 30)                 + 
    formatters.addEspacos('CEDRED' , 30)                                + 
    formatters.addEspacos(' ', 10)                                      + 
    '1'                                                                 + 
    formatters.addTrailingZeros(req.query.DataGeracaoArquivo , 8)       + 
    formatters.addTrailingZeros(req.query.HoraGeracaoArquivo , 6)       + 
    formatters.addTrailingZeros(req.query.NumeroRemessa, 6)             + 
    '087'                                                               + 
    formatters.addTrailingZeros(0, 5)                                   + 
    formatters.addEspacos(' ', 20)                                      + 
    formatters.addEspacos(' ', 20)                                      + 
    formatters.addEspacos(' ', 29);                   

// Aqui preciso inserir uma quebra de linha já tentei o \n e não funcionou

Resultado = Resultado +
    formatters.addTrailingZeros(req.query.Nrbanco, 3)                   + 
    '0001'                                                              + 
    '1'                                                                 + 
    'R'                                                                 + 
    '01'                                                                + 
    '  '                                                                + 
    '045'                                                               + 
    ' '                                                                 + 
    formatters.addTrailingZeros(req.query.TipoInscricao, 1)             + 
    formatters.addTrailingZeros(req.query.IncricaoCedente, 15)          + 
    formatters.addTrailingZeros(req.query.Convenio, 20)                 + 
    formatters.addTrailingZeros(req.query.Agencia, 15)                  + 
    formatters.addTrailingZeros(req.query.AgenciaDigito , 1)            + 
    formatters.addTrailingZeros(req.query.Conta , 12)                   + 
    formatters.addTrailingZeros(req.query.ContaDigito , 1)              + 
    ' '                                                                 + 
    formatters.addEspacos(req.query.Cedente , 30)                       + 
    formatters.addEspacos(' ', 40)                                      + 
    formatters.addEspacos(' ', 40)                                      + 
    formatters.addTrailingZeros(req.query.NumeroRemessa, 8)             + 
    formatters.addTrailingZeros(req.query.DataGeracaoArquivo , 8)       + 
    formatters.addTrailingZeros('0' , 8)                                + 
    formatters.addTrailingZeros('0' , 33);                                

var stream = Fs.createWriteStream("C:/16/consignment.txt"); stream.Once('open', Function(fd) { stream.write(Result); stream end.(); });

I tried other ways to print this variable in txt format breaking line and I was unsuccessful, thank you if anyone has any suggestions.

1 answer

2


Have you tried concatenating the \r\n at the end of what you want to be each line?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.