mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +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
|
||||
|
||||
```js
|
||||
await infisical.connect({
|
||||
import infisical from "infisical-node";
|
||||
|
||||
infisical.connect({
|
||||
token: "your_infisical_token",
|
||||
});
|
||||
```
|
||||
@@ -72,31 +74,31 @@ These examples demonstrate how to store and fetch environment variables from [In
|
||||
### Get a value
|
||||
|
||||
```js
|
||||
const value = infisical.get("SOME_KEY");
|
||||
const value = await infisical.getSecret("SOME_KEY");
|
||||
```
|
||||
|
||||
### Example with Express
|
||||
|
||||
```js
|
||||
const express = require("express");
|
||||
const port = 3000;
|
||||
const infisical = require("infisical-node");
|
||||
import infisical from "infisical-node";
|
||||
import express from "express";
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
||||
const main = async () => {
|
||||
await infisical.connect({
|
||||
token: "st.xxx.xxx",
|
||||
});
|
||||
await infisical.connect({
|
||||
token: "st.xxx.xxx",
|
||||
});
|
||||
|
||||
// your application logic
|
||||
// your application logic
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.send(`Howdy, ${infisical.get("NAME")}!`);
|
||||
});
|
||||
app.get("/", async (req, res) => {
|
||||
const name = await infisical.getSecret("NAME");
|
||||
res.send(`Hello! My name is: ${name.secretValue}`);
|
||||
});
|
||||
|
||||
app.listen(port, async () => {
|
||||
console.log(`App listening on port ${port}`);
|
||||
});
|
||||
};
|
||||
app.listen(PORT, async () => {
|
||||
console.log(`App listening on port ${port}`);
|
||||
});
|
||||
```
|
||||
|
||||
<Warning>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
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
|
||||
|
||||
@@ -12,14 +12,42 @@ Run `npm` to add `infisical-node` to your project.
|
||||
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.
|
||||
|
||||
### 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).
|
||||
|
||||
<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`)
|
||||
</ResponseField>
|
||||
<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 name="debug" type="boolean" default="false">
|
||||
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>
|
||||
</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
|
||||
|
||||
### infisical.getSecret(secretName, options)
|
||||
|
||||
```js
|
||||
const secret = await infisical.getSecret("API_KEY");
|
||||
const value = secret.secretValue; // get its value
|
||||
```
|
||||
|
||||
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`.
|
||||
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
The key of the secret to retrieve
|
||||
</ResponseField>
|
||||
@@ -120,13 +128,12 @@ By default, `getSecret()` returns a personal secret. If not found, it returns a
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
```js
|
||||
const secret = await infisical.getSecret("API_KEY");
|
||||
const value = secret.secretValue; // get its value
|
||||
```
|
||||
|
||||
### infisical.createSecret(secretName, secretValue, options)
|
||||
|
||||
```js
|
||||
const newApiKey = await infisical.createSecret("API_KEY", "FOO");
|
||||
```
|
||||
|
||||
Create a new secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
@@ -143,12 +150,12 @@ Create a new secret in Infisical.
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
```js
|
||||
const newApiKey = await infisical.createSecret("API_KEY", "FOO");
|
||||
```
|
||||
|
||||
### infisical.updateSecret(secretName, secretValue, options)
|
||||
|
||||
```js
|
||||
const updatedApiKey = await infisical.updateSecret("API_KEY", "BAR");
|
||||
```
|
||||
|
||||
Update an existing secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
@@ -165,12 +172,12 @@ Update an existing secret in Infisical.
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
```js
|
||||
const updatedApiKey = await infisical.updateSecret("API_KEY", "BAR");
|
||||
```
|
||||
|
||||
### infisical.deleteSecret(secretName, options)
|
||||
|
||||
```js
|
||||
const deletedSecret = await infisical.deleteSecret("API_KEY");
|
||||
```
|
||||
|
||||
Delete a secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
@@ -184,10 +191,6 @@ Delete a secret in Infisical.
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
```js
|
||||
const deletedSecret = await infisical.deleteSecret("API_KEY");
|
||||
```
|
||||
|
||||
## Example with Express
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user