Clerk Node.js SDK
Create a Clerk application
You need to create a Clerk application in your Clerk Dashboard before you can set up Clerk Node.js. For more information, check out our Set up your application guide.
Install @clerk/clerk-sdk-node
Once a Clerk application has been created, you can install and then start using Clerk Node.js in your application. An ESM module for the Clerk Node SDK is available under the @clerk/clerk-sdk-node
npm package.
Set environment variables
Below is an example of an .env.local
file.
Pro tip! If you are signed into your Clerk Dashboard, your secret key should become visible by clicking on the eye icon. Otherwise, you can find your keys in the Clerk Dashboard on the API Keys page.
Available methods
All resource operations are mounted as sub-APIs on the clerkClient
object. To access the resource operations, you must first instantiate a clerkClient
instance.
Multi-session applications
If Clerk is running in multi-session mode, it's important to ensure your frontend sends the Session ID that is making the request.
Our middleware will look for a query string parameter named _clerk_session_id
. If this parameter is not found, the middleware will instead choose the last active session, which may be subject to race conditions and should not be relied on for authenticating actions.
Connect/Express middlewares
The Clerk Node SDK offers two middlewares to authenticate your backend endpoints.
Error handling
Node SDK functions throw errors (ClerkAPIResponseError
) when something goes wrong. You'll need to catch them in a try/catch
block and handle them gracefully. For example:
Feedback
Last updated on