Checks
a collection of utility functions for checking the environment of the code is running on.
export const isServer = () => typeof window === "undefined";
export const isClient = () => typeof window !== "undefined";
export const isDev = () => process.env.NODE_ENV === "development";
export const isProd = () => process.env.NODE_ENV === "production";
export const isTest = () => process.env.NODE_ENV === "test";
// Next.js runtime checks
export const isNode = () => process.env.NEXT_RUNTIME === "nodejs";
export const isEdge = () => process.env.NEXT_RUNTIME === "edge";
Installation
Usage
import { isServer } from "@/utils/checks";
const document = isServer() ? undefined : document;