Treats

Treats

  • Getting Started

›Main Concepts

Getting Started

  • Installation

Tutorial

  • 01. Creating Your First Page
  • 02. Using Redux
  • 03. Using GraphQL
  • 04. Fetch Data for SSR
  • 05. Adding Addons

Main Concepts

  • Overview
  • Routing
  • Localization
  • Code-splitting
  • Redux
  • GraphQL Client
  • Middlewares
  • Helpers
  • Server-side Events
  • Server-side Template
  • Server-side Rendering
  • Custom Server App
  • Custom Client Initialization
  • Custom React App
  • Runtime Config
  • Build Config
  • Environment Variables
  • Code Generator
  • Scripts
  • Addons
  • Typescript
  • Workbox

API Reference

  • Overview
  • Filesystem Hooks
  • Components
  • Server
  • Client
  • Router
  • Intl
  • Locale Data
  • Helmet
  • Redux
  • Graphql

Authoring Addons

  • Overview
  • Helpers
  • Middlewares
  • Generators
  • Wrapping Up

Addons

  • Treats Addons List

Contributing

  • How To Contribute

FAQ

  • FAQs

Environment Variables

Treats Server can receive several environment variables:

  1. TREATS_PORT - To specify which port our server will be ran, defaults to 3000.
  2. TREATS_LOG_LEVEL - To specify log level according to npm logging level, defaults to info in non-development mode or silly on development mode. The followings are available:
  error, 
  warn, 
  info, 
  verbose, 
  debug, 
  silly
  1. TREATS_CONFIG_DIR - To specify runtime config file path, Defaults to <PROJECT_ROOT_DIR>/treats.runtime-config.json/. If file is non-existant then runtime config won't be initialized.

All environment variables will be available in process.env.** object in our code. There's also several build environment variables that we can use if for example we want our code to only exists in specific build target or build environment.

  1. NODE_ENV - To check which environment are our build currently targetting. Environment can be specified using env flag on treats build CLI, for example:
treats build --env production

OR

treats build --env staging
  1. BUILD_TARGET - To check which build target our code is currently built for, there's 2 build target that is currently available: server for server-side bundle and client for your browser bundle.

So if we want our code to specifically run only in browser we can do this:

if(process.env.BUILD_TARGET === "client") {
    const $ = require("jQuery");
}
← Build ConfigCode Generator →
Tokopedia Open Source
Copyright © 2019 Tokopedia OSS