npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@enfexia/carbone-express

v0.0.10

Published

Express API for calling Carbone with a file caching layer.

Downloads

10

Readme

carbone-copy-api

npm downloads License img

Express library that provides and interface for generating documents from templates and data. It provides a local file storage cache that means callers do not have to upload the template for each render. Callers should should store cache keys/hashes and check if templates exist before generation.

This is a wrapper around carbone, please refer to their documentation for more detail. The API follows their recommendations.

Prerequisites

This library will require LibreOffice installed to do pdf generation.

See image: alpine-node-libreoffice.

Installation

npm i @bcgov/carbone-copy-api

Configuration

There are several configuration variables that allow for customization.

| Config Var | ENV Var | Default | Notes | | --- | --- | --- | --- | | fileUploadsDir | CACHE_DIR | /tmp/carbone-files | This is the root location to read/write files. Error will be thrown if directory does not exist and cannot be created. Default is operating system temp file location. | | formFieldName | UPLOAD_FIELD_NAME | template | Field name for multipart form data upload when uploading templates via /template api. Default is 'template' | | maxFileSize | UPLOAD_FILE_SIZE | 25MB | Limit size of template files. Uses the bytes library for parsing values. Default is '25MB' | | maxFileCount | UPLOAD_FILE_COUNT | 1 | Limit the number of files uploaded per call. Default is 1, not recommended to use any other value. | | startCarbone | START_CARBONE | true | If true, then the carbone converter will be started on application start. This will ensure that the first call to /render will not incur the overhead of starting the converter. Default is 'true' |

NOTE: maxFileSize uses the bytes library for parsing values.

Options

const carboneCopyApi = require('@bcgov/carbone-copy-api');
const options = {
    fileUploadsDir: '/tmp/my-application-holding/files',
    formFieldName: 'files',
    maxFileSize: '50MB',
    maxFileCount: 1,
    startCarbone: true
};
carboneCopyApi.init(options);

Environment Variables

export CACHE_DIR = '/tmp/my-application-holding/files'
export UPLOAD_FIELD_NAME = 'files'
export UPLOAD_FILE_SIZE = '50MB'
export UPLOAD_FILE_COUNT = 1
export START_CARBONE = 'true'
const carboneCopyApi = require('@bcgov/carbone-copy-api');
carboneCopyApi.init();

Usage

The mount function accepts an express app, a path and configuration options (optional). Once mounted, you can view the OpenAPI spec at /docs wherever it is mounted.

Examples

The following mounts the carbone-copy-api at the root of the server.

const carboneCopyApi = require('@bcgov/carbone-copy-api');

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
...
carboneCopyApi.mount(app, '/');

The following mounts the carbone-copy-api to an alternate path on the server.

const carboneCopyApi = require('@bcgov/carbone-copy-api');

const options = {
   fileUploadsDir: '/tmp/my-application-holding/files',
   formFieldName: 'template',
   maxFileSize: '50MB',
   maxFileCount: 1,
   startCarbone: true
};

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
...
carboneCopyApi.mount(app, '/api/cc/v1', options);