Blog>
Snippets

Initializing TanStack Config in Your Project

Demonstrate how to install and initialize TanStack Config in a new JavaScript project, including setting up a basic configuration file.
// First, install TanStack Config using npm or yarn
// npm install @tanstack/config
// or
// yarn add @tanstack/config
This command installs the TanStack Config package into your project.
import { createConfig } from '@tanstack/config';

// Define your configuration schema
const schema = {
  // Define your schema here
};

// Initialize your configuration
const config = createConfig({
  schema,
  sources: [
    {
      source: 'env', // Load configuration from environment variables
      prefix: 'APP_', // Optional prefix for environment variables
    },
  ],
});
This snippet demonstrates how to import the createConfig function from the TanStack Config package, define a configuration schema, and initialize the configuration with the given schema. It also shows how to load configuration values from environment variables with an optional prefix.