local a json file from Public folder - node.js

I am working a nodejs back-end project. So I have a json file tryList.json saved in public folder. Also in the folder, I have a html file. What should I put in the tag of the html file so that I can load the data from tryList.json?
I am trying to import the data into the front end js code, which will be used in data visualization later.
Thanks

Related

How to read xlsx content downloaded using content-disposition node

Is there any method to read the downloaded file content(not the file name) using node js? I'm getting my downloaded file content-disposition: attachment;filename=hello11.xlsx like this. I want provide the URI to my excel data extraction function. but couldn't figure out how to get the URI because my get Request returns nothing but a file downloaded to the browser.
I found a similar question but it's using java

Unable to use puppeteer in a nodejs app on cpanel?

I am using puppeteer in my nodejs application to convert html file into pdf. This is working fine in my local server and pdf is getting generated. But this is not working in cPanel. I am getting error similar to this. I tried everything mentioned on that but nothing works.
I tried setting the executable path of chrome in puppeteer in cpanel but in vain. Errpr =>
Failed to launch the browser process!
/home/xxx/public_html/xxx/node_modules/puppeteer/.local-chromium/linux-1002410/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory
I tried different packages like html-pdf and node-pdf-generator. But the problem is I have designed some ejs templates according to chrome and then I am generating html files from these ejs templates. After that I am saving the pdf file in buffer and uploading this buffer to google bucket.
Flow: ejs templates -> html file -> pdf buffer -> stream buffer to gc
bucket
In other packages I am facing these issues:
Either the template is not coming as expected
Or The package has no option of storing generated pdf file in buffer.
Any solution or a different library?

Is there any way I can display pdfs uploaded in my files using nodejs and ejs?

I created a way to upload files using Multer in my files then display their information to my frontend. My challenge is opening the uploaded PDF as when I click the link to open it says that it cannot get.
You need to specify your static files in Express.
Use app.use(express.static('public')) to specify that your static files are located on public folder.
And for get a file you don't need to add public in the url, for example:
http://localhost:3000/pdf/mypdf.pdf
See this documentation

Downloading file from Dropbox API for use in Python Environment with Apache Tika on Heroku

I'm trying to use Dropbox as a cloud-based file receptacle for an app/script. The script, written in Python, needs to take PDFs from the Dropbox and use the tika-python wrapper to convert to string.
I'm able to connect to the Dropbox API and use the files_download_to_file() method to download the PDFs to disk, and then use the tika from_file() method to pull that download file from the disk to process. Example:
# Download ex.pdf to local disk
dbx.files_download_to_file('/my_local_path/ex_on_disk.pdf', '/my_dropbox_path/ex.pdf')
from tika import parser
parsed = parser.from_file('ex_on_disk.pdf')
The problem is that I'm planning on running this app on something like Heroku. I don't think I'm able to save anything locally and then access it again. I'm not sure how to get something from the Dropbox API that can be directly referenced by the tika wrapper to run the same as above. I think the PHP SDK has a file_get_contents and a file_put_contents set of methods but it doesn't appear to have a companion in the Python SDK.
I've tried using the shareable links in place of a filename but that hasn't worked. Any ideas? I know there's also the files_download method which downloads the FileMetadata object but I have no idea what to do with this and am having trouble finding more about it.
TLDR; How can I reference a file on Dropbox with a filename string such as 'example.pdf' to be used in another function that is trying to read a file from disk, without saving that Dropbox file to disk?
I figured it out. I used the files_download method to get the byte string and then use the from_buffer method of tika instead:
md, response = dbx.files_download(path)
file_contents = response.content
parsed = parser.from_buffer(file_contents)

About folder structure in nodejs

Actually , I am beginner in nodejs field . So want to know where to place(folder name) what file (like html file , css file , js file other files).
What is the correct folder structure(formating) of the nodejs web application.
ie...
public folder is for (html , css , image etc)
I am confused. Can you help. And want to know what is the need of this type of folder convention.Is it is a standard or any other reason. ?
You can create to folder in your main project.
lib - this will hold all the server related logic.
public - this will have the client side related files. here you can create the sub folders named as : html, css and js. At the time of execution this folder you can serve as static files.
main
---lib
---public
--------html
--------css
--------js
server.js
config.json

Resources