0

I am trying to parse my csv file in server and return back the information after parsing and analyzing the data in csv.

I am not that used to express and i dont know any view engine.

I plan to use

res.sendFile(path.join(__dirname, "/index.html"));

to host my index file.

What are the other way than ajax and view template that can I send data to the index.html with sendFile.

I am sending JSON files from server to client

Any kind of help is appreciated !!!

Pravin Poudel
  • 1,433
  • 3
  • 16
  • 38
  • 2
    I get lose in this part: **once file is parsed and i need to send the data back to the index.html**. What is your flow? #1 user enter to your home page (index.html), html loads on the web browser, then user with a button ask for something and you return the csv to populate an html table or #2 user enter to your home page (index.html) and you return the csv data in a table or something like that? – JRichardsz Dec 29 '21 at 22:34
  • user enter the home page and there user upload a csv file and get back the desired information (which is processed in backend) and that information need to be seen in index.html – Pravin Poudel Dec 29 '21 at 22:42
  • #1 Does de @Quentin answer helped you? #2 How the information(csv) is showed? #3 Are you open to use javascript with ajax to deliver a pleasant experience to your user? – JRichardsz Dec 29 '21 at 22:46
  • yes, it seems ajax is good option. I don't need to show csv, i just need to show the processed information like count of occurrence of something in csv and it can be in table. Yes, i am open to use ajax as i will need to submit my file to the server anyway. – Pravin Poudel Dec 29 '21 at 22:57
  • You will find a lot of information to develop an [upload](https://stackoverflow.com/questions/23691194/node-express-file-upload) feature. This question is related to the second part of your flow: How to return json as response of upload file in nodejs express?. If you agree with that, change the title to help you. If not, continue explaining to us – JRichardsz Dec 29 '21 at 23:04
  • Yes, my question is related to returning a response of upload file. I thought that i can parse the data that i get as an ajax response, and display it. Please correct me – Pravin Poudel Dec 29 '21 at 23:32
  • Yes, it is possible – JRichardsz Dec 30 '21 at 00:06

1 Answers1

2

When a client (such as a browser) makes a request you can respond with one thing.

You can respond with:

  • The contents of a file as you are now (although you should use the static middleware instead of rolling your own end point handlers (without caching) one-by-one)
  • A template + some data rendered into a single file (using the view engines you haven't gotten around to learning yet)
  • Some JSON (typically in response to an Ajax request so the a JS program running in an HTML document get add more data to the existing HTML page)
  • Something else

If sending an unmodified file is not what you want, then don't use sendFile.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335