Merge pull request #429 from Infisical/check-vercel

Add docs for Node SDK
This commit is contained in:
BlackMagiq
2023-03-12 23:04:48 +07:00
committed by GitHub
2 changed files with 115 additions and 6 deletions

View File

@@ -49,6 +49,11 @@
"icon": "server",
"url": "self-hosting"
},
{
"name": "SDK",
"icon": "puzzle-piece",
"url": "sdk"
},
{
"name": "API Reference",
"icon": "cloud",
@@ -128,10 +133,8 @@
"integrations/platforms/docker-compose"
]
},
"integrations/platforms/kubernetes",
"integrations/frameworks/terraform",
{
"group": "AWS",
"pages": [
@@ -139,20 +142,16 @@
"integrations/cloud/aws-secret-manager"
]
},
"integrations/cloud/heroku",
"integrations/cloud/vercel",
"integrations/cloud/netlify",
"integrations/cloud/render",
"integrations/cloud/flyio",
"integrations/cloud/azure-key-vault",
"integrations/cicd/githubactions",
"integrations/cicd/gitlab",
"integrations/cicd/circleci",
"integrations/cicd/travisci",
"integrations/frameworks/react",
"integrations/frameworks/vue",
"integrations/frameworks/express",
@@ -192,6 +191,12 @@
"self-hosting/configuration/email"
]
},
{
"group": "SDK",
"pages": [
"sdk/overview/usage"
]
},
{
"group": "Overview",
"pages": [

104
docs/sdk/overview/usage.mdx Normal file
View 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>