I have a simple HTML file:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Test of skill</title>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<body>
<div id="mydiv">y</div>
</body>
</html>
I can use the following code to read it and assign the content to a string variable:
fs.readFile('./test-responsive.html','utf8', function(err, data){
if(err) throw err;
var myObj = {
tpl: data
};
}
The above code works great, but when I do the following, it doesn't work.
var myObj2 = {
tpl: " <!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Test of skill</title>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<body>
<div id="mydiv">y</div>
</body>
</html> "
};
I know it has something to do with line break and escaping, but how the line break works in the above two different situation? It would be great if you can explain the difference. Thank you!
why I don't need to escape or use "\" when reading from file to string?