Pravin Poudel
Pravin Poudel

Reputation: 1536

how to send data on file with sendFile in express

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 !!!

Upvotes: 0

Views: 508

Answers (1)

Quentin
Quentin

Reputation: 944301

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.

Upvotes: 2

Related Questions