Pogodoc
Get Started

TypeScript

Get started with Pogodoc using TypeScript and Node.js - from installation to your first document render

TypeScript Quickstart

Welcome! This guide will help you get started with Pogodoc using TypeScript and Node.js. You'll learn how to install the SDK, authenticate, and generate your first document in minutes.

Prerequisites

Before you begin, make sure you have:

Quick Start Guide

Install the SDK

Install the Pogodoc SDK using your preferred package manager:

npm install @pogodoc/sdk
yarn add @pogodoc/sdk
pnpm add @pogodoc/sdk
bun add @pogodoc/sdk

Initialize the Client

Create a Pogodoc client with your API token. You can get your token from the API tokens page.

import { PogodocClient } from '@pogodoc/sdk';

const pogodoc = new PogodocClient({
  token: '<YOUR_API_TOKEN>',
});

Using Environment Variables

For better security, store your API token in an environment variable:

.env
POGODOC_API_TOKEN=your_token_here

The SDK will automatically read the POGODOC_API_TOKEN environment variable if no token is provided.

Generate Your First Document

Now you're ready to generate a document! Here's a simple example using an EJS template:

const template = `
  <!DOCTYPE html>
  <html>
    <head>
      <title>Invoice</title>
      <style>
        body { font-family: Arial, sans-serif; }
        h1 { color: #333; }
      </style>
    </head>
    <body>
      <h1>Invoice for <%= customerName %></h1>
      <p>Amount: $<%= amount %></p>
      <p>Date: <%= date %></p>
    </body>
  </html>
`;

const data = {
  customerName: 'John Doe',
  amount: 1299.99,
  date: new Date().toLocaleDateString(),
};

const response = await pogodoc.generateDocument({
  template,
  data,
  renderConfig: {
    type: 'ejs',
    target: 'pdf',
  },
});

// Get the URL to your generated PDF
console.log('Document URL:', response.output?.data.url);

Success!

Your document is now generated and available at the returned URL. The URL is publicly accessible and can be shared or downloaded.

Next Steps

Now that you've generated your first document, explore the detailed SDK documentation: