Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

Node.js Available Methods

All resource operations are mounted as sub-APIs on the clerkClient object. You can find the full list of available operations in the Clerk Backend SDK documentation. To access a resource, you must first instantiate a clerkClient instance.

Instantiate a default clerkClient instance

If you would like to use the default instance of clerkClient provided by the SDK, you can provide the CLERK_SECRET_KEY as an environment variable and instantiate clerkClient without passing configuration options.

import { clerkClient } from '@clerk/clerk-sdk-node'; const userList = await clerkClient.users.getUserList();

If you are interested in a certain resource, you can destructure clerkClient to access just that resource.:

import { sessions } from '@clerk/clerk-sdk-node'; const sessionList = await sessions.getSessionList();

Instantiate a custom clerkClient instance

If you would like to customize the behavior of the SDK, you can instantiate a clerkClient instance yourself by calling createClerkClient and passing in options.

The example below shows how to use createClerkClient to create a clerkClient instance and pass a Clerk secret key instead of setting a CLERK_SECRET_KEY environment variable.

import { createClerkClient } from '@clerk/clerk-sdk-node'; const clerkClient = createClerkClient({ secretKey: '{{secret}}' }); const clientList = await clerkClient.clients.getClientList();
const Clerk = require('@clerk/clerk-sdk-node/cjs/instance').default; const clerkClient = Clerk({ secretKey: '{{secret}}' }); clerkClient.sessions .getSessionList() .then((sessions) => console.log(sessions)) .catch((error) => console.error(error));

Customizing resources

The following options are available for you to customize the behaviour of the clerkClient object.

Most options can also be set as environment variables so that you don't need to pass anything to the constructor.

OptionDescriptionDefaultEnvironment variable
secretKeyServer key for api.clerk.com. Can be found in your Clerk Dashboard on the API Keys(opens in a new tab) page.noneCLERK_SECRET_KEY
apiVersionAPI version to usev4CLERK_API_VERSION
apiUrlFor debugginghttps://api.clerk.comCLERK_API_URL
httpOptionsHTTP client options{}N/A

For every option, the resolution is as follows, in order of descending precedence:

  • option passed
  • environment variable (if applicable)
  • default

This means that if you pass an option to the constructor, it will always take precedence over an environment variable.

Another available environment variable is CLERK_LOGGING. You can set its value to true to enable additional logging that may be of use when debugging an issue.

What did you think of this content?

Clerk © 2024