Skip to main content
The $app/environment module provides access to environment variables and build-time information about your SvelteKit application.

browser

browser
boolean
true if the app is running in the browser, false otherwise.
import { browser } from '$app/environment';

if (browser) {
  // This code will only run in the browser
  console.log('Running in browser');
}

dev

dev
boolean
Whether the dev server is running. This is not guaranteed to correspond to NODE_ENV or MODE.
import { dev } from '$app/environment';

if (dev) {
  console.log('Development mode');
}

building

building
boolean
SvelteKit analyses your app during the build step by running it. During this process, building is true. This also applies during prerendering.
import { building } from '$app/environment';

if (building) {
  console.log('Building application');
}

version

version
string
The value of config.kit.version.name.
import { version } from '$app/environment';

console.log(`App version: ${version}`);

Usage Examples

Conditional Browser Code

import { browser } from '$app/environment';

if (browser) {
  // Access browser APIs safely
  localStorage.setItem('visited', 'true');
}

Development-Only Features

import { dev } from '$app/environment';

if (dev) {
  // Enable debugging features only in development
  window.__DEBUG__ = true;
}

Build-Time Optimization

import { building } from '$app/environment';

if (!building) {
  // Skip expensive operations during build
  initializeAnalytics();
}