I have a web server running on a BBB and serving an html page with some tabular data and control buttons. On demand, I would like to download a file of the tabular data to the client. I can create, write, and delete the file with the fs module.
In the web page, I have HTML like Click to download.
When I click, I get a download file named “Sample.txt” but the contents of the file are the HTML code of the web page. I think this is because I am not handling the download command in the server side JavaScript.
Can someone explain what JavaScript should be in the server to catch the ‘download’ command and return the specified file? What should the “socket.on(???, downloadFile);” look like? What’s the correct way to return the file so the client browser correctly saves it?
I can provide the rest of the code if needed, but it seems to be working - I just can’t find references to handling the file download from that element.
Thanks.