{"id":15663,"library":"jsreport-client","title":"jsreport Node.js Client","description":"jsreport-client is a Node.js remote client library designed to interact with a jsreport server, facilitating programmatic report generation and management of jsreport entities. It acts as a wrapper around the jsreport REST API, abstracting HTTP communication to allow developers to render PDF reports, work with templates, and manage data from a Node.js application. The package is currently at version 1.2.1, with its last update in March 2021. Releases are infrequent, suggesting it is in a maintenance phase rather than active feature development. Key differentiators include its promise-based API for rendering and its seamless integration with remote jsreport instances, supporting both on-premise servers and the jsreportonline SaaS offering. It handles request retry mechanisms and error reporting, providing a robust interface for report automation.","status":"maintenance","version":"1.2.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/jsreport/nodejs-client","tags":["javascript"],"install":[{"cmd":"npm install jsreport-client","lang":"bash","label":"npm"},{"cmd":"yarn add jsreport-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsreport-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Handles underlying HTTP requests to the jsreport server, replacing the deprecated 'request' package since v1.1.0.","package":"axios"}],"imports":[{"note":"The package exports a factory function as its default export. TypeScript users typically import it as 'Client'. CommonJS users use require directly. For jsreport v3 and newer, the package name changed to @jsreport/nodejs-client, but this package (jsreport-client) is for older versions.","wrong":"const Client = require('jsreport-client');","symbol":"Client","correct":"import Client from 'jsreport-client';"},{"note":"The imported 'Client' is a factory function, not a class constructor. It should be called directly to create an instance with an options object.","wrong":"const client = new Client('http://localhost:5488');","symbol":"jsreportClientInstance","correct":"const client = Client({ serverUrl: 'http://localhost:5488' });"}],"quickstart":{"code":"import Client from 'jsreport-client';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nasync function generateReport() {\n  // Initialize the jsreport client with the server URL (and optional credentials)\n  const client = Client({\n    serverUrl: process.env.JSREPORT_SERVER_URL ?? 'http://localhost:5488',\n    username: process.env.JSREPORT_USERNAME,\n    password: process.env.JSREPORT_PASSWORD,\n    // Ensure strictSSL is false for self-signed certificates in development\n    strictSSL: process.env.NODE_ENV === 'production' // Only enforce SSL for production\n  });\n\n  try {\n    // Render a report using a raw template definition and some data\n    console.log('Attempting to render report...');\n    const response = await client.render({\n      template: {\n        content: '<h1>Hello {{:name}} from jsreport!</h1><p>Generated at {{new Date().toLocaleString()}}</p>',\n        engine: 'handlebars',\n        recipe: 'chrome-pdf' // Assuming chrome-pdf recipe is available on the server\n      },\n      data: {\n        name: 'JSReport User'\n      }\n    });\n\n    // Save the generated report content to a PDF file\n    const outputPath = path.join(process.cwd(), 'hello-jsreport-report.pdf');\n    await fs.writeFile(outputPath, await response.content());\n    console.log(`Report successfully generated and saved to ${outputPath}`);\n  } catch (e: any) {\n    console.error('Error generating report:', e.message);\n    if (e.statusCode) {\n      console.error('Status Code:', e.statusCode);\n      console.error('Response Body:', e.body);\n    }\n    process.exit(1);\n  }\n}\n\ngenerateReport();","lang":"typescript","description":"Demonstrates how to initialize the jsreport client and render a PDF report using a simple Handlebars template and data, saving the output to a file."},"warnings":[{"fix":"Update all `client.render()` calls to use `await` or `.then()` for Promise-based handling. Review the jsreport v2 migration guide for other potential breaking changes in the server-side API.","message":"Version 1.0.0 introduced significant breaking changes aligned with jsreport v2. The `render` method no longer accepts a callback and instead returns a Promise. Direct access to Node.js HTTP response streams was also changed.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Review any custom HTTP client configurations passed to `jsreport-client` and adapt them to `axios` compatible options. Ensure network proxies or certificate handling configured for `request` are correctly translated for `axios`.","message":"In version 1.1.0, the underlying HTTP client was switched from the `request` package to `axios`. This change might affect applications that relied on specific `request` options, custom HTTP agents, or behavior unique to the `request` library.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Avoid `strictSSL:false` in production environments. For self-signed certificates, properly configure your Node.js environment with the trusted CA certificate. Use environment variables to conditionally set `strictSSL` for development vs. production (e.g., `strictSSL: process.env.NODE_ENV === 'production'`).","message":"Version 1.1.2 replicated the `strictSSL:false` option with `axios`. While convenient for development with self-signed certificates, relying on `strictSSL:false` in production can pose security risks by disabling SSL certificate validation.","severity":"gotcha","affected_versions":">=1.1.2"},{"fix":"Monitor memory usage on both the client and jsreport server when dealing with very large report payloads. Ensure the jsreport server itself is configured to handle large requests efficiently.","message":"Version 1.2.0 made infinite body size the default for HTTP requests. While this prevents issues with large report data, it could potentially mask underlying problems with excessively large payloads or resource exhaustion if not managed properly by the jsreport server.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"For jsreport v3+ servers, consider migrating to `@jsreport/nodejs-client` (install via `npm i @jsreport/nodejs-client`). If sticking with `jsreport-client` (v1.x), ensure your jsreport server is running a compatible v2 version.","message":"This `jsreport-client` package (version 1.x) is designed for jsreport v2 servers. Newer jsreport server versions (v3 and above) are typically designed to work with the `@jsreport/nodejs-client` package, which has a different import path and potentially updated API. Using this older client with a newer server might lead to compatibility issues.","severity":"gotcha","affected_versions":"1.x"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Verify that your jsreport server is running and listening on `http://localhost:5488` (or the configured `serverUrl`). Check firewall rules or network connectivity. The `jsreport-cli` can be used to start a local server.","cause":"The jsreport server is not running or is not accessible at the specified URL and port.","error":"Error: connect ECONNREFUSED 127.0.0.1:5488"},{"fix":"If in a development environment and the certificate is intentionally self-signed, initialize the client with `strictSSL: false`. For production, ensure the client's Node.js environment trusts the server's SSL certificate by adding the CA to the system's trusted certificates or specifying a custom `ca` option if supported by the client.","cause":"The jsreport client is attempting to connect to an HTTPS server with a self-signed or untrusted SSL certificate, and `strictSSL` is enabled.","error":"Error: self signed certificate in certificate chain"},{"fix":"Ensure you are importing and initializing the client factory function correctly: `import Client from 'jsreport-client'; const client = Client({ serverUrl: '...' });`. Double-check the package name in `package.json` to confirm it's `jsreport-client`.","cause":"The `client` object was not correctly instantiated, or the `jsreport-client` package itself was not imported correctly.","error":"TypeError: client.render is not a function"}],"ecosystem":"npm"}