Publishing to npm

Publish your public-facing Fern TypeScript SDK to the npm registry. After following the steps on this page, you’ll have a versioned package published on npm.

Versioned package published on npm

This page assumes that you have:

Configure generators.yml

Your generators.yml should live in your source repository (or on your local machine), not the repository that contains your TypeScript SDK code.
1

Configure output location

In the group for your TypeScript SDK, change the output location in from local-file-system (the default) to npm to indicate that Fern should publish your package directly to the npm registry:

generators.yml
1groups:
2 ts-sdk: # Group name for your TypeScript SDK
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 2.5.0
6 output:
7 location: npm
2

Add a unique package name

Your package name must be unique in the npm repository, otherwise publishing your SDK to npm will fail.

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 2.5.0
6 output:
7 location: npm
8 package-name: your-package-name
3

Configure namespaceExport

The namespaceExport option controls the name of the generated client. This is the name customers use to import your SDK (import { your-client-name } from 'your-package-name';).

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 2.5.0
6 output:
7 location: npm
8 package-name: your-package-name
9 config:
10 namespaceExport: YourClientName # must be PascalCase
4

Add repository location

Add the path to the GitHub repository containing your TypeScript SDK:

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 2.5.0
6 output:
7 location: npm
8 package-name: your-package-name
9 config:
10 namespaceExport: YourClientName
11 github:
12 repository: your-org/company-typescript

Generate an npm token

1

Log into npm

Log into npm or create a new account.

3

Generate Token

Click on Generate New Token, then choose the appropriate token type.

For more information on access tokens and which type to choose, see npm’s About access tokens documentation.
  1. Select Classic Token
  2. Name your token and select Automation as the token type.
  3. Click Generate Token.
Save your new token – it won’t be displayed after you leave the page.
Creating NPM Automation Token
  1. Select Granular Access Token.
  2. Name your token.
  3. Set an expiration.
  4. Configure your token’s access to packages and scopes.
  5. Configure your token’s access to organizations. In order to fill this out, you must have at least one organization already configured in npm. See Creating an organization for more information.
  6. Optionally fill out additional permissions according to your organization’s requirements.
  7. Click Generate Token.
Save your new token – it won’t be displayed after you leave the page.
Creating Granular Access Token

Configure npm publication

Choose how you want to authenticate and publish your SDK to npm. You can use GitHub workflows for automated releases or publish directly via the CLI.

1

Configure npm authentication token

Add token: ${NPM_TOKEN} to generators.yml to tell Fern to use the NPM_TOKEN environment variable for authentication when publishing to the npm registry.

1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 2.5.0
6 output:
7 location: npm
8 package-name: name-of-your-package
9 token: ${NPM_TOKEN}
10 config:
11 namespaceExport: YourClientName
12 github:
13 repository: your-org/your-repository
2

Set npm environment variable

Set the NPM_TOKEN environment variable on your local machine:

$export NPM_TOKEN=your-actual-npm-token
3

Regenerate your SDK

Regenerating your SDK tags the new release with the version number you specified and initiates a Fern-generated publishing workflow in your TypeScript SDK repository that publishes your release to npm.

$fern generate --group ts-sdk --version <version>

Local machine output will verify that the release is pushed to your repository and tagged with the version you specified. Log back into npm and navigate to Packages to see your new release.