Initialize the server client
Configure the combined server client and its optional services.
Import from the server entry in trusted server code. It does not import the React SDK.
import { createCarpoServerClient } from '@carpodev/carpo-sdk/server'
export const carpo = createCarpoServerClient({
apiUrl: process.env.CARPO_API_URL!,
projectId: process.env.CARPO_PROJECT_ID!,
environment: 'production',
database: {
url: process.env.CARPO_DATABASE_URL!,
authToken: process.env.CARPO_DATABASE_TOKEN!,
},
storage: {
bucketId: process.env.CARPO_STORAGE_BUCKET_ID!,
apiKey: process.env.CARPO_STORAGE_API_KEY!,
},
})The combined client always exposes auth and functions. database and storage are added only when their configuration is provided. The database configuration follows the official @libsql/client Config type. The storage configuration takes a bucket ID and a project API key with the storage scope.
Set the database URL, database access token, and Storage API key in server environment variables or a secrets manager. The project ID, API URL, environment, and bucket ID are not secrets.
Close the database client
When a Database connection is configured, call carpo.close() when the owning server process or task no longer needs it. close() closes the libSQL connection. If no Database client was configured, there is no database connection to close.
For services that do not need a combined client, import a focused factory from @carpodev/carpo-sdk/server/auth, @carpodev/carpo-sdk/server/database, or @carpodev/carpo-sdk/server/storage. The request scoped client is exported from @carpodev/carpo-sdk/server/request.
Select an environment
Set environment to production or development. It defaults to production. Keep the environment consistent with the Project Auth instance, Database permissions, bucket, or Function deployment you intend to use.