Environment Client
Environment
Get and load environment.
The Environment Client class provides methods to interact with the environment.
Get
Get the environment data.
const stashbase = createEnvClient(process.env.SB_ENVIRONMENT_API_KEY)
const { data, error } = await stashbase.environemnt.get()
// check for errors
if (error) {
// handle error
} else {
// do something with the data
}Load
This is the easiest way to load an environment in a Node.js application. When using this method, the SDK client will get the secrets from the environment and inject them as environment variables in the application process.
Parameters
This method takes optional object parameter with the following optional properties:
Prop
Type
Example
const { error } = await stashbase.environment.load({
// enable only for production
enabled: process.env.NODE_ENV === 'production',
})
// check for errors
if (error) {
// handle error
}Load or throw
This method is similar to load but it will throw an error if something goes wrong instead of returning the error as property.
Parameters
This method takes optional object parameter with the following optional properties:
Prop
Type
Example
// this will throw an error if something goes wrong
await stashbase.environment.loadOrThrow()