mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 09:26:14 +00:00
Update node SDK docs, positioning of examples
This commit is contained in:
@@ -64,7 +64,9 @@ These examples demonstrate how to store and fetch environment variables from [In
|
|||||||
### Initialize the Infisical client
|
### Initialize the Infisical client
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await infisical.connect({
|
import infisical from "infisical-node";
|
||||||
|
|
||||||
|
infisical.connect({
|
||||||
token: "your_infisical_token",
|
token: "your_infisical_token",
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@@ -72,31 +74,31 @@ These examples demonstrate how to store and fetch environment variables from [In
|
|||||||
### Get a value
|
### Get a value
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const value = infisical.get("SOME_KEY");
|
const value = await infisical.getSecret("SOME_KEY");
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example with Express
|
### Example with Express
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const express = require("express");
|
import infisical from "infisical-node";
|
||||||
const port = 3000;
|
import express from "express";
|
||||||
const infisical = require("infisical-node");
|
const app = express();
|
||||||
|
const PORT = 3000;
|
||||||
|
|
||||||
const main = async () => {
|
await infisical.connect({
|
||||||
await infisical.connect({
|
token: "st.xxx.xxx",
|
||||||
token: "st.xxx.xxx",
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// your application logic
|
// your application logic
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", async (req, res) => {
|
||||||
res.send(`Howdy, ${infisical.get("NAME")}!`);
|
const name = await infisical.getSecret("NAME");
|
||||||
});
|
res.send(`Hello! My name is: ${name.secretValue}`);
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(port, async () => {
|
app.listen(PORT, async () => {
|
||||||
console.log(`App listening on port ${port}`);
|
console.log(`App listening on port ${port}`);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<Warning>
|
<Warning>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
title: "Node"
|
title: "Node"
|
||||||
---
|
---
|
||||||
|
|
||||||
If you're working with Node.js, the official [infisical-node](https://github.com/Infisical/infisical-node) package is the easiest way to fetch secrets for your application.
|
If you're working with Node.js, the official [infisical-node](https://github.com/Infisical/infisical-node) package is the easiest way to fetch and work with ecrets for your application.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -12,14 +12,42 @@ Run `npm` to add `infisical-node` to your project.
|
|||||||
npm install infisical-node --save
|
npm install infisical-node --save
|
||||||
```
|
```
|
||||||
|
|
||||||
## Initialization
|
## Configuration
|
||||||
|
|
||||||
Call `connect()` with your Infisical token as early as possible in the main entry module of your application. This initializes the global instance of the SDK, which can be accessed anywhere in your application.
|
Import the SDK and call `connect()` with your Infisical token as early as possible in the main entry module of your application. This initializes the global instance of the SDK, which can be accessed anywhere in your application.
|
||||||
|
|
||||||
For multiple Infisical projects or creating multiple SDK instances, use `createConnection()` instead. This returns a local SDK instance, independent of the global instance.
|
For multiple Infisical projects or creating multiple SDK instances, use `createConnection()` instead. This returns a local SDK instance, independent of the global instance.
|
||||||
|
|
||||||
### infisical.connect(options)
|
### infisical.connect(options)
|
||||||
|
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab title="ES6">
|
||||||
|
```js
|
||||||
|
import infisical from "infisical-node";
|
||||||
|
|
||||||
|
infisical.connect({
|
||||||
|
token: "your_infisical_token",
|
||||||
|
});
|
||||||
|
|
||||||
|
// your app logic
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab title="ES5">
|
||||||
|
```js
|
||||||
|
const infisical = require("infisical-node");
|
||||||
|
|
||||||
|
infisical.connect({
|
||||||
|
token: "your_infisical_token"
|
||||||
|
});
|
||||||
|
|
||||||
|
// your app logic
|
||||||
|
````
|
||||||
|
</Tab>
|
||||||
|
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
Updates the global instance of the Infisical client with a connection to an Infisical project with the [Infisical Token](/getting-started/dashboard/token).
|
Updates the global instance of the Infisical client with a connection to an Infisical project with the [Infisical Token](/getting-started/dashboard/token).
|
||||||
|
|
||||||
<ResponseField name="options" type="object">
|
<ResponseField name="options" type="object">
|
||||||
@@ -37,7 +65,7 @@ Updates the global instance of the Infisical client with a connection to an Infi
|
|||||||
`https://app.infisical.com`)
|
`https://app.infisical.com`)
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
<ResponseField name="cacheTTL" type="number" default="300">
|
<ResponseField name="cacheTTL" type="number" default="300">
|
||||||
Time-to-live (in seconds) for cached secrets. If set to 0, data is cached indefinitely.
|
Time-to-live (in seconds) for refreshing cached secrets. Default: `300`.
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
<ResponseField name="debug" type="boolean" default="false">
|
<ResponseField name="debug" type="boolean" default="false">
|
||||||
Whether or not debug mode is on
|
Whether or not debug mode is on
|
||||||
@@ -74,41 +102,21 @@ This method is useful if you wish to connect to two or more Infisical projects w
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
|
|
||||||
<Tabs>
|
|
||||||
<Tab title="ES6">
|
|
||||||
```js
|
|
||||||
import infisical from "infisical-node";
|
|
||||||
|
|
||||||
infisical.connect({
|
|
||||||
token: "your_infisical_token",
|
|
||||||
});
|
|
||||||
|
|
||||||
// your app logic
|
|
||||||
```
|
|
||||||
|
|
||||||
</Tab>
|
|
||||||
<Tab title="ES5">
|
|
||||||
```js
|
|
||||||
const infisical = require("infisical-node");
|
|
||||||
|
|
||||||
infisical.connect({
|
|
||||||
token: "your_infisical_token"
|
|
||||||
});
|
|
||||||
|
|
||||||
// your app logic
|
|
||||||
````
|
|
||||||
</Tab>
|
|
||||||
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### infisical.getSecret(secretName, options)
|
### infisical.getSecret(secretName, options)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const secret = await infisical.getSecret("API_KEY");
|
||||||
|
const value = secret.secretValue; // get its value
|
||||||
|
```
|
||||||
|
|
||||||
Retrieve a secret from Infisical.
|
Retrieve a secret from Infisical.
|
||||||
|
|
||||||
By default, `getSecret()` returns a personal secret. If not found, it returns a shared secret, or tries to retrieve the value from `process.env`.
|
By default, `getSecret()` returns a personal secret. If not found, it returns a shared secret, or tries to retrieve the value from `process.env`.
|
||||||
|
|
||||||
|
|
||||||
<ResponseField name="secretName" type="string" required>
|
<ResponseField name="secretName" type="string" required>
|
||||||
The key of the secret to retrieve
|
The key of the secret to retrieve
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
@@ -120,13 +128,12 @@ By default, `getSecret()` returns a personal secret. If not found, it returns a
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
|
|
||||||
```js
|
|
||||||
const secret = await infisical.getSecret("API_KEY");
|
|
||||||
const value = secret.secretValue; // get its value
|
|
||||||
```
|
|
||||||
|
|
||||||
### infisical.createSecret(secretName, secretValue, options)
|
### infisical.createSecret(secretName, secretValue, options)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const newApiKey = await infisical.createSecret("API_KEY", "FOO");
|
||||||
|
```
|
||||||
|
|
||||||
Create a new secret in Infisical.
|
Create a new secret in Infisical.
|
||||||
|
|
||||||
<ResponseField name="secretName" type="string" required>
|
<ResponseField name="secretName" type="string" required>
|
||||||
@@ -143,12 +150,12 @@ Create a new secret in Infisical.
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
|
|
||||||
```js
|
|
||||||
const newApiKey = await infisical.createSecret("API_KEY", "FOO");
|
|
||||||
```
|
|
||||||
|
|
||||||
### infisical.updateSecret(secretName, secretValue, options)
|
### infisical.updateSecret(secretName, secretValue, options)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const updatedApiKey = await infisical.updateSecret("API_KEY", "BAR");
|
||||||
|
```
|
||||||
|
|
||||||
Update an existing secret in Infisical.
|
Update an existing secret in Infisical.
|
||||||
|
|
||||||
<ResponseField name="secretName" type="string" required>
|
<ResponseField name="secretName" type="string" required>
|
||||||
@@ -165,12 +172,12 @@ Update an existing secret in Infisical.
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
|
|
||||||
```js
|
|
||||||
const updatedApiKey = await infisical.updateSecret("API_KEY", "BAR");
|
|
||||||
```
|
|
||||||
|
|
||||||
### infisical.deleteSecret(secretName, options)
|
### infisical.deleteSecret(secretName, options)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const deletedSecret = await infisical.deleteSecret("API_KEY");
|
||||||
|
```
|
||||||
|
|
||||||
Delete a secret in Infisical.
|
Delete a secret in Infisical.
|
||||||
|
|
||||||
<ResponseField name="secretName" type="string" required>
|
<ResponseField name="secretName" type="string" required>
|
||||||
@@ -184,10 +191,6 @@ Delete a secret in Infisical.
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
</ResponseField>
|
</ResponseField>
|
||||||
|
|
||||||
```js
|
|
||||||
const deletedSecret = await infisical.deleteSecret("API_KEY");
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example with Express
|
## Example with Express
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user