Reputation: 347
I am unable to read PDF file in node js.
My code looks like this:
var router = express.Router();
router.get('/api/resource', function(req, res) {
filePath = req.query.resource;
fs.readFile(filePath, function(err, file) {
res.writeHead(200, {"Content-Type" : "application/pdf" });
res.write(file, "binary");
res.end();
});
});
But i am not able to get the content of the file in the response.
Upvotes: 1
Views: 6379
Reputation: 802
as other people said the question itself is not very clear. If the function you are trying to implement would let user to download or view a PDF from the browser, then the post below may help you to fine the answer. How to send a pdf file from Node/Express app to the browser
However, if you are expecting to read the PDF file into some other format like JSON. Then you may want to check out some 3rd party modules that npm has.
Good luck.
Upvotes: 1