Installation Guide for the Freemius JS/TS SDK
This installation guide will help you get up and running with the Freemius TypeScript/JavaScript SDK in your SaaS application.
Prerequisites
- Node.js, version 20 or higher or other platforms like Deno or Bun.
- A package manager: npm, yarn, or pnpm
We also recommend using TypeScript for type safety and an improved development experience; however, you can use the SDK in plain JavaScript projects as well.
You will also need to have a Freemius account and a product set up. If you have not done so already, please follow the getting started guide.
Support for Bun and Deno is experimental. Please report any issues you encounter.
Installation
Depending on your preferred package manager, run one of the following commands in your project directory:
- npm
- Yarn
- pnpm
- Bun
npm install @freemius/sdk @freemius/checkout zod
yarn add @freemius/sdk @freemius/checkout zod
pnpm add @freemius/sdk @freemius/checkout zod
bun add @freemius/sdk @freemius/checkout zod
@freemius/checkout
is required for the checkout generation feature. You can also use it on your frontend to render the checkout modal.zod
is required for schema validation.
Retrieving Keys from the Developer Dashboard
Next, please head over to the Developer Dashboard and navigate to the Settings page for your product and selec the API & Keys tab.
Now scroll down to the Usage examples, copy the code snippet written in the .env
format.
You will need these keys to configure the SDK in your application. We recommend storing them in environment variables using the standard .env
file format.
Make sure to keep your Secret Key and Bearer Token secure and do not expose them in client-side code or public repositories.
Configuration
We recommend creating an instance of the Freemius SDK in a separate module and exporting it for use throughout your application.
import { Freemius } from '@freemius/sdk';
export const freemius = new Freemius({
productId: process.env.FREEMIUS_PRODUCT_ID!,
apiKey: process.env.FREEMIUS_API_KEY!,
secretKey: process.env.FREEMIUS_SECRET_KEY!,
publicKey: process.env.FREEMIUS_PUBLIC_KEY!,
});
To use it, simply import the freemius
instance from the module you created.
import { freemius } from './lib/freemius';
async function main() {
const pricing = await freemius.pricing.retrieve();
console.log(pricing);
}
Please continue reading to learn more about the different features of the SDK and how to use them in your application.