Skip to content

Migration

In a Node.js app if you are already calling dotenv/config, you can replace it with varlock/auto-load.

index.js
import 'dotenv/config';
import 'varlock/auto-load';

In some cases where dotenv is being called deep under the hood by another dependency, you may instead want to swap it in as a dependency override. See our migrate from dotenv guide for more information.

We must replace framework’s existing .env logic with Varlock. Our framework integrations handle most of the work for you. After installation, simply follow the instructions in the relevant integration guide to set up Varlock in your project. Usually this involves adding a new plugin to the existing build system or framework’s config file.

In some cases, a code-level integration may be challenging or impossible. In this case you can use varlock run to boot your application with env vars injected from Varlock. For example varlock run -- your-app. Sometimes you may need to use this alongside a deeper integration, for example to feed env vars into external tools or additional scripts.

If you’re currently using import.meta.env or process.env, your code will still work after switching to Varlock. However, we recommend using varlock’s ENV object for better type-safety and an improved developer experience.

index.js
// Before (import.meta.env)
console.log(import.meta.env.SOMEVAR);
// After (ENV)
import { ENV } from 'varlock/env';
console.log(ENV.SOMEVAR);

intellisense

See our integrations section for more information.