Skip to content

Integration

There are a few different ways to integrate Varlock into your application.

The most universal way to use varlock in your code is via varlock run.

Terminal window
varlock run -- <your-command>

This will validate your environment variables and then run the command you provided with the validated environment variables injected into the process.

varlock can be used in any Node.js application by importing the auto-load module. This will automatically load the environment variables into process.env.

example-index.js
import 'varlock/auto-load';
const MY_CONFIG_ITEM = process.env.MY_CONFIG_ITEM;

If you are using dotenv to load your environment variables, you can use the overrides feature to use varlock instead.

package.json
"overrides": {
"dotenv": "varlock"
}

You can also use varlock in your package.json scripts by using the varlock run command.

package.json
"scripts": {
"start": "varlock run -- node index.js"
}