diff --git a/docs/getting-started/quickstart.mdx b/docs/getting-started/quickstart.mdx index f19bd1120..8a2ef75f5 100644 --- a/docs/getting-started/quickstart.mdx +++ b/docs/getting-started/quickstart.mdx @@ -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}`); + }); ``` diff --git a/docs/sdks/languages/node.mdx b/docs/sdks/languages/node.mdx index fe5e969f8..28ce8cf00 100644 --- a/docs/sdks/languages/node.mdx +++ b/docs/sdks/languages/node.mdx @@ -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) + + + + ```js + import infisical from "infisical-node"; + + infisical.connect({ + token: "your_infisical_token", + }); + + // your app logic + ``` + + + + ```js + const infisical = require("infisical-node"); + + infisical.connect({ + token: "your_infisical_token" + }); + + // your app logic + ```` + + + + Updates the global instance of the Infisical client with a connection to an Infisical project with the [Infisical Token](/getting-started/dashboard/token). @@ -37,7 +65,7 @@ Updates the global instance of the Infisical client with a connection to an Infi `https://app.infisical.com`) - 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`. 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 - - - ```js - import infisical from "infisical-node"; - - infisical.connect({ - token: "your_infisical_token", - }); - - // your app logic - ``` - - - - ```js - const infisical = require("infisical-node"); - - infisical.connect({ - token: "your_infisical_token" - }); - - // your app logic - ```` - - - ## 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`. + The key of the secret to retrieve @@ -120,13 +128,12 @@ By default, `getSecret()` returns a personal secret. If not found, it returns a -```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. @@ -143,12 +150,12 @@ Create a new secret in Infisical. -```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. @@ -165,12 +172,12 @@ Update an existing secret in Infisical. -```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. @@ -184,10 +191,6 @@ Delete a secret in Infisical. -```js -const deletedSecret = await infisical.deleteSecret("API_KEY"); -``` - ## Example with Express ```js