mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Add docs for Node SDK
This commit is contained in:
@@ -49,6 +49,11 @@
|
|||||||
"icon": "server",
|
"icon": "server",
|
||||||
"url": "self-hosting"
|
"url": "self-hosting"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "SDK",
|
||||||
|
"icon": "puzzle-piece",
|
||||||
|
"url": "sdk"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "API Reference",
|
"name": "API Reference",
|
||||||
"icon": "cloud",
|
"icon": "cloud",
|
||||||
@@ -128,10 +133,8 @@
|
|||||||
"integrations/platforms/docker-compose"
|
"integrations/platforms/docker-compose"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"integrations/platforms/kubernetes",
|
"integrations/platforms/kubernetes",
|
||||||
"integrations/frameworks/terraform",
|
"integrations/frameworks/terraform",
|
||||||
|
|
||||||
{
|
{
|
||||||
"group": "AWS",
|
"group": "AWS",
|
||||||
"pages": [
|
"pages": [
|
||||||
@@ -139,20 +142,16 @@
|
|||||||
"integrations/cloud/aws-secret-manager"
|
"integrations/cloud/aws-secret-manager"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"integrations/cloud/heroku",
|
"integrations/cloud/heroku",
|
||||||
"integrations/cloud/vercel",
|
"integrations/cloud/vercel",
|
||||||
"integrations/cloud/netlify",
|
"integrations/cloud/netlify",
|
||||||
"integrations/cloud/render",
|
"integrations/cloud/render",
|
||||||
"integrations/cloud/flyio",
|
"integrations/cloud/flyio",
|
||||||
|
|
||||||
"integrations/cloud/azure-key-vault",
|
"integrations/cloud/azure-key-vault",
|
||||||
|
|
||||||
"integrations/cicd/githubactions",
|
"integrations/cicd/githubactions",
|
||||||
"integrations/cicd/gitlab",
|
"integrations/cicd/gitlab",
|
||||||
"integrations/cicd/circleci",
|
"integrations/cicd/circleci",
|
||||||
"integrations/cicd/travisci",
|
"integrations/cicd/travisci",
|
||||||
|
|
||||||
"integrations/frameworks/react",
|
"integrations/frameworks/react",
|
||||||
"integrations/frameworks/vue",
|
"integrations/frameworks/vue",
|
||||||
"integrations/frameworks/express",
|
"integrations/frameworks/express",
|
||||||
@@ -192,6 +191,12 @@
|
|||||||
"self-hosting/configuration/email"
|
"self-hosting/configuration/email"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"group": "SDK",
|
||||||
|
"pages": [
|
||||||
|
"sdk/overview/usage"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"group": "Overview",
|
"group": "Overview",
|
||||||
"pages": [
|
"pages": [
|
||||||
|
|||||||
104
docs/sdk/overview/usage.mdx
Normal file
104
docs/sdk/overview/usage.mdx
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
---
|
||||||
|
title: "Usage"
|
||||||
|
---
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
We're currently expanding the functionality of the Javascript SDK and working
|
||||||
|
on mirror SDKs for other languages like Python as well. Follow this GitHub
|
||||||
|
[issue](https://github.com/Infisical/infisical/issues/320) to stay updated.
|
||||||
|
</Note>
|
||||||
|
|
||||||
|
Infisical provides a [Node SDK](https://github.com/Infisical/infisical-node) that users can easily install into their applications and use to fetch their secrets.
|
||||||
|
|
||||||
|
With the SDK, users can currently fetch back secrets and define default values.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab title="Javascript">
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm install infisical-node
|
||||||
|
```
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
```js
|
||||||
|
// ES6 syntax
|
||||||
|
import infisical from "infisical-node";
|
||||||
|
|
||||||
|
// ES5 syntax
|
||||||
|
const infisical = require("infisical-node");
|
||||||
|
```
|
||||||
|
|
||||||
|
## Initialization
|
||||||
|
|
||||||
|
If your app only needs to connect to one Infisical project, you should use `infisical.connect`. If you need to connect to multiple Infisical projects, use `infisical.createConnection`.
|
||||||
|
|
||||||
|
Both `connect` and `createConnection` take a parameter `token` and pull in the secrets accessible by that Infisical token.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// using async-await (recommended)
|
||||||
|
await infisical.connect({
|
||||||
|
token: "your_infisical_token",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
// using promise chaining
|
||||||
|
infisical.connect({
|
||||||
|
token: "your_infisical_token"
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log('Success!)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('Error: ', err);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
| Option | Description | Default Value |
|
||||||
|
| -------------------- | ----------------------------------------------------------- | --------------------------- |
|
||||||
|
| `token` | ❗️ An Infisical Token to be used to fetch secrets | `None` |
|
||||||
|
| `siteURL` | Site URL of Infisical to connect to | `https://app.infisical.com` |
|
||||||
|
| `attachToProcessEnv` | Whether or not to attach fetched secrets to `process.env` | `False` |
|
||||||
|
| `defaultValues` | Default values for secrets if they aren't fetched/passed in | `{}` |
|
||||||
|
|
||||||
|
## Access a Secret Value
|
||||||
|
|
||||||
|
```js
|
||||||
|
const dbURL = infisical.getSecretValue("DB_URL");
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example with Express
|
||||||
|
|
||||||
|
```js
|
||||||
|
const express = require("express");
|
||||||
|
const port = 3000;
|
||||||
|
const infisical = require("infisical-node");
|
||||||
|
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
// access value
|
||||||
|
const name = infisical.getSecret("NAME");
|
||||||
|
|
||||||
|
res.send(`Hello! My name is: ${name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(port, async () => {
|
||||||
|
// initialize client
|
||||||
|
await infisical.connect({
|
||||||
|
token: "YOUR_INFISICAL_TOKEN",
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`App listening on port ${port}`);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
</Tab>
|
||||||
|
<Tab title="Python">
|
||||||
|
Coming soon.
|
||||||
|
</Tab>
|
||||||
|
|
||||||
|
</Tabs>
|
||||||
Reference in New Issue
Block a user