node.js – open pdf file


I have a controller that I’m working with APIs and as a result of these processes, I easily save the pdf from the API as ‘filename.pdf’ in my folder named ‘pdfs’. But after these operations, I want to open this pdf file that I saved in the browser. ow can I do that?

I tried to open it by typing but I get the error:

window is not a function

Where am I missing?

    const { 
    } = req.body.datas
    const config = {
        headers: {
            "Content-Type" : "application/json",
    const { data } = await`xxxxx`,{

    const result = (data.result.BarcodeZpl)
    var time =
    var filename = `frontend/public/pdfs/label${time}.pdf`;
     here i save the pdf


You are mixing front-end and back-end code. Your axios call and the save of the PDF is happening on your server in the back-end. is something that happens in the browser (the front-end). You can’t do that in the back-end.

For the front-end to display a PDF that you have stored in the back-end, you will have to make a request from the front-end to your back-end (some sort of GET request) and then have your back-end stream the PDF that it has stored in its file system to the front-end with the proper content-type so the browser can then do something with it.

You don’t show enough overall context for us to see if you should be doing that in the request handler you show some code for or if that should be in a different request handler or if you should be sending back a redirect to the other URL. We’d have to understand the entire operation here and what you’re trying to do.

Answered By – jfriend00

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published