Express server send empty PDF file Express server send empty PDF file express express

Express server send empty PDF file


I've seen this when using connect-livereload middleware. The problem is that connect-livereload is injecting a js code snippet into the pdf data stream. It can also cause problems with other non-html data. The good news is that this should only cause problems during development (you shouldn't be loading this middleware in production.)

This was recently fixed but a lot of templates include an older version so check your package.json file and get the latest version if necessary. The most recent connect-livereload version is 0.5.3.


If the e.g. ignore: ['.pdf'] line does not work, it might be due to fact that you do not query for a resource with the related suffix.

E.g. If you query for a resource with an id:

localhost:9000/api/export/getExport?destinationId=56179bb36bc51bb00836c3ed

you cannot filter for the file suffix. What you can do instead is to filter via the path:

app.use( require( 'connect-livereload' )( {  ignore: [ /api\/export\/getExport.*/ ]} ) );

Have a look at the other possible options at connect-livereload.