Node.js SDK
The official CredVault SDK for JavaScript and TypeScript applications. Whether you're building a web application, REST API, or serverless function, this SDK provides everything you need to work with CredVault.
Why Use the Node.js SDK?
The Node.js SDK is designed for the JavaScript ecosystem. It works seamlessly with Express, Fastify, Next.js, and other popular frameworks. TypeScript developers benefit from complete type definitions that provide excellent IDE support and catch errors at compile time.
The SDK uses modern JavaScript conventions with async/await syntax. All methods return Promises, making it easy to work with asynchronous operations. Error handling follows familiar patterns with try/catch blocks.
Installation
The SDK is available through npm, the standard package manager for Node.js applications. Add it to your project with a single command:
npm install credvault-sdk
You'll also want to ensure you have Node.js version 16.0 or higher installed. The SDK uses modern JavaScript features that require a recent runtime.
Connecting to CredVault
Before making API calls, you need to create a client instance. The client maintains your authentication credentials and provides access to all platform resources.
import { CredVault } from 'credvault-sdk';
const client = new CredVault({
apiKey: process.env.CREDVAULT_API_KEY,
});
For server-side applications, use your API key. Store the key as an environment variable (CREDVAULT_API_KEY) rather than hardcoding it in your source code. This keeps credentials secure and makes it easy to use different keys for different environments.
For applications acting on behalf of users, you can authenticate with a bearer token instead. Tokens are obtained through the authentication flow and should be refreshed before they expire.
Working with Data
The data resource provides methods for all standard database operations.
Listing clusters returns all database clusters in your account. Each cluster object includes its name, region, status, and connection details.
Querying collections retrieves documents matching your criteria. You can filter by field values, sort by specific fields, limit the number of results, and paginate through large result sets.
Inserting documents adds new records to a collection. You can insert a single document or multiple documents in one operation. CredVault returns the inserted documents with their generated IDs.
Updating documents modifies existing records. Specify which documents to update using a filter, then provide the changes to apply. Updates can set new values, remove fields, or increment numeric values.
Deleting documents removes records from a collection. Like updates, you specify which documents to delete using a filter. Deletion is permanent, so consider implementing soft deletes for recoverable data.
Handling Errors
When operations fail, the SDK throws descriptive errors. Wrap your API calls in try/catch blocks to handle errors gracefully.
Common error scenarios include authentication failures (invalid or expired credentials), not found errors (accessing resources that don't exist), validation errors (malformed requests), and rate limiting (too many requests in a short period).
Resources Available
The SDK organizes functionality into resources that mirror the platform's capabilities:
- auth — User authentication and profile management
- data — Database clusters and document operations
- cie — Intelligence Engine for machine learning
- webhooks — Event notification configuration
- functions — Serverless function management
- triggers — Database event automation
- backups — Backup and restore operations
- schema — Schema analysis and indexing
- apiKeys — API key management
- metrics — Platform monitoring data
- logs — Activity and audit logs
- notifications — User notification preferences
- settings — Account configuration
Best Practices
Keep your SDK updated. We regularly release improvements and bug fixes. Check for updates periodically to benefit from the latest features.
Use environment variables. Never commit API keys to source control. Use environment variables or secret management tools.
Handle errors appropriately. Don't ignore errors silently. Log them for debugging and provide meaningful feedback to users when operations fail.
Implement retry logic. Network operations can fail temporarily. Implement exponential backoff for transient errors.
For complete method documentation and examples, refer to the SDK's README on GitHub or explore the TypeScript type definitions in your IDE.