Monday, 5 June 2017

Creating a webtask that uses node fs and relative file paths

I have a simple node app that takes a PDF file and return the contents in JSON. The app is built using the pdf2json module, and only works through the command line (with local files).

I would like to run this app from a remote server, either through a standalone node app or a webtask. If I attach a PDF to a post request, will I be able to reference the relative file path? Or do I need to save the pdf to server before running the function?

Here is the working snippet I have now:

const fs = require('fs')
const PDFParser = require('./node_modules/pdf2json/PDFParser');

const pdfParser = new PDFParser();

pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
    const res = JSON.stringify(pdfParser.getAllFieldsTypes());
    console.log(res);
});

pdfParser.loadPDF("./path/to/my.pdf");


via pingo

No comments:

Post a Comment