mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
105 lines
2.7 KiB
Plaintext
105 lines
2.7 KiB
Plaintext
---
|
|
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>
|