Docs

Node.js Available Methods

Caution

On January 8, 2025, the Node SDK will no longer be available. Upgrade to the Express SDK.

All resource operations are mounted as sub-APIs on the clerkClient object. You can find the full list of available operations in the JavaScript 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()
const pkg = require('@clerk/clerk-sdk-node')
const clerkClient = pkg.default

clerkClient.sessions
  .getSessionList()
  .then((sessions) => console.log(sessions))
  .catch((error) => console.error(error))

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: 'YOUR_SECRET_KEY' })

const clientList = await clerkClient.clients.getClientList()
const Clerk = require('@clerk/clerk-sdk-node/cjs/instance').default

const clerkClient = Clerk({ secretKey: 'YOUR_SECRET_KEY' })

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.

Note

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 on the API keys page in the Clerk Dashboard.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.

Feedback

What did you think of this content?

Last updated on