Can not display strings with line break in Node.js

0

I need to work with css in a js script for nodejs. However if the css has some line break the console.log does not work.

const fs = require('fs');
var contents = fs.readFileSync('style.css').toString();
console.log(contents);

However, I take the spaces out to see that the content has been loaded:

console.log(contents.replace(/\s/g, "\r"););

The problem is that I need to display with all line breaks in my project.

I'm starting on Nodejs. If someone can explain to me why this is resolved.

I'm running nodeJS inside php exec:

$exec = exec($nodejs." p.js ", $output);

echo $exec;
    
asked by anonymous 17.07.2018 / 08:37

1 answer

0

After many tests I discovered that every line break in php is received by $ output as an array.

echo in $ exec only takes the last line break.

This way to display the content was just to use a foreach!

$exec = exec($nodejs." p.js ", $output);

foreach($output as $line){ echo $line."\n";}
    
18.07.2018 / 06:28