Blog>
Snippets

Basic Setup of TanStack Config

Show how to install and perform a basic setup of TanStack Config in a Node.js e-commerce project, demonstrating the initialization and a simple configuration file creation.
// Step 1: Installing TanStack Config
// Open your terminal and run:
// npm install @tanstack/config
This code snippet is for installing TanStack Config, a library for managing application settings and configurations, in your Node.js e-commerce project.
const { createConfig } = require('@tanstack/config');

// Step 2: Initialize and create a basic configuration
const config = createConfig({
  // Define your configuration settings
  default: {
    API_URL: 'https://api.example.com',
    PORT: 3000
  }
});

console.log(config.API_URL); // Outputs: https://api.example.com
This code initializes the TanStack Config in your project with a simple configuration object containing default settings like API URL and server port. It demonstrates how to access these settings using the config object.