Back to Infisical

Inject secrets during local development

docs/documentation/platform/secrets-mgmt/quick-starts/deliver-first-secret.mdx

0.162.183.6 KB
Original Source

import ConfigureProject from "/snippets/documentation/platform/secrets-mgmt/configure-project.mdx";

This quickstart guide walks you through the recommended secrets management workflow for local development. You'll create a project, add secrets to one of its environments, and inject them into your local application using the Infisical CLI, all without needing a .env file.

<Info> Prerequisites: <ConfigureProject />

Step 2: Connect your app to Infisical

Now that you've set up a project that holds your secrets in Infisical, you can connect your application and give it access to those secrets at runtime.

Authenticate with the CLI

Authenticate with the Infisical CLI by running infisical login:

bash
infisical login

This prompts you to select your hosting option, then opens your browser to complete the login.

<Note> In a containerized environment such as WSL 2 or Codespaces, run `infisical login -i` to avoid browser-based login. </Note>

Connect your project

Next, connect your application to your Infisical project:

<Steps> <Step> In your application's directory, link it to the Infisical project you created by running [`infisical init`](/cli/commands/init):
```bash
infisical init
```
</Step> <Step> Follow the prompts to select the organization/project where you created your secrets earlier. This writes a `.infisical.json` file to your project with [local project settings](/cli/project-config):
```json .infisical.json
{
  "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "defaultEnvironment": "",
  "gitBranchToEnvironmentMapping": null
}
```

<Note>
`.infisical.json` files contain no secrets and are safe to commit to version control systems like git.
</Note>
</Step> </Steps>

Step 3: Inject secrets into your app

Now that your Infisical project is configured within your application, Infisical can provide the secrets.

Start your application by wrapping its start command with infisical run:

<CodeGroup> ```bash Node.js infisical run --env=dev -- npm run dev ```
bash
infisical run --env=dev -- flask run
bash
infisical run --env=dev -- go run main.go
</CodeGroup>

Infisical fetches the secrets and injects them as environment variables. This lets your application read the secrets from its environment at runtime.

<Check> You can now manage your application's secrets through Infisical without needing a `.env` file. </Check>

Next Steps

<CardGroup cols={2}> <Card title="Core Concepts" icon="book" href="/documentation/platform/secrets-mgmt/concepts/secrets-mgmt"> Understand how projects, environments, folders, and secrets fit together. </Card> <Card title="Secrets Delivery" icon="truck-fast" href="/documentation/platform/secrets-mgmt/concepts/secrets-delivery"> Deliver secrets to production with SDKs, agents, Kubernetes, and CI/CD. </Card> <Card title="Local Development Guide" icon="laptop-code" href="/documentation/guides/local-development"> Set up a secure local development workflow for your whole team. </Card> <Card title="Access Control" icon="shield-halved" href="/documentation/platform/secrets-mgmt/concepts/access-control"> Scope who can access which environments and paths. </Card> </CardGroup>