### Install Docparser Node.js Client Source: https://github.com/docparser/docparser-node/blob/master/README.md This command installs the `docparser-node` library from npm, making it available for use in your JavaScript projects. ```sh npm install docparser-node ``` -------------------------------- ### Initialize Docparser JavaScript Client Source: https://github.com/docparser/docparser-node/blob/master/README.md Create a new instance of the Docparser client by providing your valid Docparser API Token. This client object will be used for all subsequent API calls to interact with the Docparser service. ```js var docparser = require('docparser-node'); var client = new docparser.Client("validAPIKey"); ``` -------------------------------- ### Docparser API Client Methods Overview Source: https://github.com/docparser/docparser-node/blob/master/README.md Overview of the main methods available in the Docparser JavaScript client for interacting with the Docparser API, including authentication, parser management, and various document upload/import options. ```APIDOC DocparserClient: ping(): Promise Description: Tests the API key authentication. getParsers(): Promise> Description: Returns a list of all document parsers in your account. Returns: An array of parser objects, e.g., [{"id":"someparserid","label":"My Document Parser"}] uploadFileByPath(parserId: string, filePath: string, options?: Object): Promise Description: Uploads a document from a local file path. Parameters: parserId: The ID of the document parser. filePath: The path to the local file. options: Optional object. remote_id: string (max 255 chars) - An arbitrary string to associate with the document. filename: string - Overrides the original filename. Returns: An object with document details, e.g., {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"} uploadFileByStream(parserId: string, stream: ReadableStream, options?: Object): Promise Description: Uploads document content from a readable stream. Parameters: parserId: The ID of the document parser. stream: A readable stream containing the file content. options: Optional object. remote_id: string (max 255 chars) - An arbitrary string to associate with the document. filename: string - Overrides the original filename. Returns: An object with document details. fetchDocumentFromURL(parserId: string, url: string, options?: Object): Promise Description: Imports a document from a publicly available URL. Parameters: parserId: The ID of the document parser. url: The HTTP(S) URL of the document. options: Optional object. remote_id: string (max 255 chars) - An arbitrary string to associate with the document. Returns: An object with document details. ``` -------------------------------- ### Test Docparser API Authentication Source: https://github.com/docparser/docparser-node/blob/master/README.md Call the `ping()` method on the Docparser client to verify if your API key is valid. The method returns a promise that resolves on successful authentication or rejects with an error on failure. ```js client.ping() .then(function() { console.log('authentication succeeded!') }) .catch(function(err) { console.log('authentication failed!') }) ``` -------------------------------- ### Fetch Document from URL to Docparser Source: https://github.com/docparser/docparser-node/blob/master/README.md Imports a document into a Docparser document parser by providing a publicly accessible HTTP(S) URL. An optional `remote_id` can be included for tracking the document throughout its processing. The method returns a promise with the import result. ```js client.fetchDocumentFromURL('someparserid', 'http://example.com/test.pdf', {remote_id: 'test'}) .then(function (result) { // => {"id":"document_id","file_size":153914,"quota_used":17,"quota_left":33,"quota_refill":"1970-01-01T00:00:00+00:00"} }) .catch(function (err) { console.log(err) }) ``` -------------------------------- ### List All Docparser Document Parsers Source: https://github.com/docparser/docparser-node/blob/master/README.md Retrieve a list of all document parsers configured in your Docparser account. The method returns a promise that resolves with an array of parser objects, each containing details like ID and label. ```js client.getParsers() .then(function (parsers) { console.log(parsers) // => [{"id":"someparserid","label":"My Document Parser"}] }) .catch(function (err) { console.log(err) }) ``` -------------------------------- ### Upload Document from Local File System to Docparser Source: https://github.com/docparser/docparser-node/blob/master/README.md Uploads a document from a specified local file path to a Docparser document parser. An optional `remote_id` can be provided for tracking purposes. The method returns a promise with the upload result. ```js client.uploadFileByPath('someparserid', './test.pdf', {remote_id: 'test'}) .then(function (result) { // => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"} }) .catch(function (err) { console.log(err) }) ``` -------------------------------- ### Upload Document from Readable Stream to Docparser Source: https://github.com/docparser/docparser-node/blob/master/README.md Uploads document content from a readable stream to a Docparser document parser. The `filename` and `remote_id` can be specified in the options object to override defaults or add metadata. The method returns a promise with the upload result. ```js client.uploadFileByStream('someparserid', fs.createReadStream('filepath'), options) .then(function (result) { // => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"} }) .catch(function (err) { console.log(err) }) ``` -------------------------------- ### Retrieve Parsed Data for Multiple Documents by Parser (Node.js) Source: https://github.com/docparser/docparser-node/blob/master/README.md Fetches the results of multiple documents parsed by a specific document parser using its `parserId`. This function allows granular filtering and ordering of the results, with additional parameters available in the official documentation. The `format` parameter allows choosing between a flat or nested array structure for the output. ```js client.getResultsByParser(parserId, {format: 'object'}) .then(function (result) { console.log(result) }) .catch(function (err) { console.log(err) }) ``` -------------------------------- ### Retrieve Parsed Data for a Single Document (Node.js) Source: https://github.com/docparser/docparser-node/blob/master/README.md Fetches the parsed data for a specific document by providing a `parserId` and the `documentId`. The `documentId` is the Docparser Document ID which is returned when importing a document through the API. The `format` parameter allows choosing between a flat or nested array structure for the output. ```js client.getResultsByDocument(parserId, documentId, {format: 'object'}) .then(function (result) { console.log(result) }) .catch(function (err) { console.log(err) }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.