0

I'm using websockets in NodeJS to create a server and I want to read a CSV file or parse a CSV file and print data on a web page but that file is updated frequently so is there a way to keep track of the updating file and print the updated data like appending the print data whenever updated?

I am able to parse csv and print data but want to keep track of updation

Alex
  • 4,844
  • 7
  • 44
  • 58
Labeo
  • 5,831
  • 13
  • 47
  • 77

1 Answers1

1

Have a look at using fs to watch a file for changes.

When this event fires for your file, you can send a socket event with the latest version of the contents of the file to the client. You will need to re-fill your file stream when this event fires, and then send the results over the socket.

Alex
  • 4,844
  • 7
  • 44
  • 58
  • i had a code that converts whole code from csv to json how to get updated data from csv will it provide or is there a way – Labeo Sep 28 '15 at 13:56
  • You can do it, by using streams and buffers. If you know the position of the end of the file before it was updated, you can read from this position, into a buffer. Check this answer carefully for more: http://stackoverflow.com/a/14971359/239036 – Alex Sep 28 '15 at 14:32
  • is there a way to get xl data row by row so that i will take a row and convert it to json and send json data, so that i can keep track of last row i have sent – Labeo Oct 01 '15 at 04:01
  • If you are streaming the data (which you would do if it's a very large file), you will need to check for a `\n` line-break. As you hopefully know, this is the signifier for a new entry / marker for end of an entry in a CSV file. – Alex Oct 01 '15 at 09:23
  • no my csv file is like a xl file it looks like an xl file but the extension is .csv – Labeo Oct 01 '15 at 11:17
  • Yes I've dealt with csv many times. In its raw string format line endings are \n ... You may need to do more research.. – Alex Oct 01 '15 at 11:37
  • it is not parsing to json – Labeo Oct 05 '15 at 08:27