Package Exports
- infisical-node
- infisical-node/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (infisical-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Open-source, end-to-end encrypted tool to manage secrets and configs across your team and infrastructure.
Links
Basic Usage
import InfisicalClient from "infisical-node";
import express from "express";
const app = express();
const PORT = 3000;
const client = new InfisicalClient({
token: "YOUR_INFISICAL_TOKEN"
});
app.get("/", async (req, res) => {
// access value
const name = await client.getSecret("NAME");
res.send(`Hello! My name is: ${name.secretValue}`);
});
app.listen(PORT, async () => {
// initialize client
console.log(`App listening on port ${port}`);
});This example demonstrates how to use the Infisical SDK with an Express application. The application retrieves a secret named "NAME" and responds to requests with a greeting that includes the secret value.
Installation
npm install infisical-nodeConfiguration
Import the SDK and create a client instance with your Infisical token.
const InfisicalClient = require("infisical-node");
const client = new InfisicalClient({
token: "your_infisical_token"
});
// your app logicUsing ES6:
import InfisicalClient from "infisical-node";
const client = new InfisicalClient({
token: "your_infisical_token"
});
// your app logicOptions
| Parameter | Type | Description |
|---|---|---|
token |
string |
An Infisical Token scoped to a project and environment. |
siteURL |
string |
Your self-hosted Infisical site URL. Default: https://app.infisical.com. |
cacheTTL |
number |
Time-to-live (in seconds) for refreshing cached secrets. Default: 300. |
debug |
boolean |
Turns debug mode on or off. Default: false. |
Caching
The SDK caches every secret and updates it periodically based on the provided cacheTTL. For example, if cacheTTL of 300 is provided, then a secret will be refetched 5 minutes after the first fetch; if the fetch fails, the cached secret is returned.
Working with Secrets
Get Secrets
const secrets = await client.getAllSecrets();Retrieve all secrets within the Infisical project and environment that client is connected to
Get Secret
Retrieve a secret from Infisical:
const secret = await client.getSecret("API_KEY");
const value = secret.secretValue; // get its valueBy default, getSecret() fetches and returns a personal secret. If not found, it returns a shared secret, or tries to retrieve the value from process.env. If a secret is fetched, getSecret() caches it to reduce excessive calls and re-fetches periodically based on the cacheTTL option (default is 300 seconds) when initializing the client — for more information, see the caching section.
To explicitly retrieve a shared secret:
const secret = await client.getSecret("API_KEY", { type: "shared" });
const value = secret.secretValue; // get its valueParameters
secretName(string): The key of the secret to retrieve.options(object, optional): An options object to specify the type of secret.type(string, optional): The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "personal".
Create Secret
Create a new secret in Infisical:
const newApiKey = await client.createSecret("API_KEY", "FOO");Parameters
secretName(string): The key of the secret to create.secretValue(string): The value of the secret.options(object, optional): An options object to specify the type of secret.type(string, optional): The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". A personal secret can only be created if a shared secret with the same name exists.
Update Secret
Update an existing secret in Infisical:
const updatedApiKey = await client.updateSecret("API_KEY", "BAR");Parameters
secretName(string): The key of the secret to update.secretValue(string): The new value of the secret.options(object, optional): An options object to specify the type of secret.type(string, optional): The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".
Delete Secret
Delete a secret in Infisical:
const deletedSecret = await client.deleteSecret("API_KEY");Parameters
secretName(string): The key of the secret to delete.options(object, optional): An options object to specify the type of secret to delete.type(string, optional): The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". Note that deleting a shared secret also deletes all associated personal secrets.
Contributing
Bug fixes, docs, and library improvements are always welcome. Please refer to our Contributing Guide for detailed information on how you can contribute.
Getting Started
If you want to familiarize yourself with the SDK, you can start by forking the repository and cloning it in your local development environment. The project requires Node.js to be installed on your machine.
After cloning the repository, install the depenencies by running the following command in the directory of your cloned repository:
$ npm installTo run existing tests, you need to make a .env at the root of this project containing a INFISICAL_TOKEN and SITE_URL. This will execute the tests against a project and environment scoped to the INFISICAL_TOKEN on a running instance of Infisical at the SITE_URL (this could be Infisical Cloud).
To run all the tests you can use the following command:
$ npm testLicense
infisical-node is distributed under the terms of the MIT license.