0

I am using angular fullstack generator for creating a web application. I want to send a file data from nodejs server to display in the Front end.But data is sent in unformatted manner since i am receiving it in a variable( as a array of strings). Plz. tell me how to get the file data as it is (in the file at server )in the front end.

My nodejs code :

 function readstack() {
 fs = require('fs')
 fs.readFile('outstack.txt', 'utf8', function (err,data) {
 if (err) {
 return console.log(err);
 }
 console.log(data);
 res.send(data); 
 });
 }
 var stackend = setTimeout(readstack,30000);

My angular controller code :

$http.get('/runtrace').success(function(response){
console.log("requested data");
$scope.output= response;

I am displaying in front end by :

 <div id="divoutput"> 
 {{output}}
 </div >
  • your question isn't clear. You are reading a .txt file from the filesystem on the server and sending it to the client for display. What is in the .txt file, and what are you expecting the display to look like? this code would just write the contents of the text file in the div. – Claies Jan 07 '16 at 11:49
  • The file i am trying to send is a file generated by some python program . It is a text file which has information of many lines but all separated.. for example say... Name: somerthing..nd many such information in lines. I the above code the second line is continued where the first line is ending.But i want the second line to be displayed as second line only(as it is generated by my python program) – ABHISHEK KUMAR TIWARI Jan 09 '16 at 14:32

1 Answers1

1

Did you try sending the file instead of reading using file system response.sendfile("yourText.txt"); ?

Monika
  • 31
  • 2