Back to Tutorials
intermediate
SDK
Complete Node.js SDK Guide
Deep dive into the CredLyr Node.js SDK for credential verification.
15 min read
6 sections
Prerequisites
- Node.js 18+ installed
- Basic JavaScript/TypeScript knowledge
- CredLyr API key
In this tutorial
Overview
The CredLyr Node.js SDK provides a type-safe, intuitive interface for integrating credential verification into your applications. This guide covers installation, configuration, and common use cases.
Installation
Install the SDK using npm or yarn.
npm install @credlyr/node-sdk
# or
yarn add @credlyr/node-sdkInitialize the Client
Create a CredLyr client instance with your API key.
import { CredLyr } from '@credlyr/node-sdk';
const credlyr = new CredLyr({
apiKey: process.env.CREDLYR_API_KEY,
// Optional: use sandbox environment
environment: 'sandbox',
});Create a Verification
Create a new verification session and get the hosted URL.
const verification = await credlyr.verifications.create({
policyId: 'pol_your_policy_id',
returnUrl: 'https://yourapp.com/callback',
metadata: {
userId: 'user_123',
orderId: 'order_456',
},
});
console.log(verification.hostedUrl);
// Redirect user to this URLRetrieve Verification Status
Check the status of a verification after completion.
const verification = await credlyr.verifications.get('ver_xxxxx');
if (verification.status === 'approved') {
console.log('Verified claims:', verification.outputClaims);
// Grant access to user
} else if (verification.status === 'denied') {
console.log('Denial reason:', verification.denialReason);
}Error Handling
Handle errors gracefully with typed exceptions.
import { CredLyrError, RateLimitError } from '@credlyr/node-sdk';
try {
const verification = await credlyr.verifications.create({ ... });
} catch (error) {
if (error instanceof RateLimitError) {
console.log('Rate limited, retry after:', error.retryAfter);
} else if (error instanceof CredLyrError) {
console.log('API error:', error.code, error.message);
}
}