Introduction
Process state and path utility module. Provides environment detection, process type checking, and path retrieval functions, serving as the foundational dependency for other modules to obtain runtime environment information. All path information comes from process.env environment variables set during boot.
Import
// CJS
const { allEnv, env, isProd, isDev, getDataDir, getLogDir } = require('ee-core/ps');
// ESM
import { allEnv, env, isProd, isDev, getDataDir, getLogDir } from 'ee-core/ps';API
allEnv()
Description: Get all environment variables of the current process. Returns: NodeJS.ProcessEnv — the complete process.env object.
env()
Description: Get the current environment name. Returns: string — environment name: 'dev', 'local', 'prod', or empty string if not set.
isProd()
Description: Whether this is a production environment (EE_ENV === 'prod'). Returns: boolean — true if production environment.
isDev()
Description: Whether this is a development environment (EE_ENV === 'dev' or 'local'). Returns: boolean — true if development environment.
isRenderer()
Description: Whether this is a renderer process (process.type === 'renderer'). Returns: boolean — true if renderer process.
isMain()
Description: Whether this is the main (browser) process (process.type === 'browser'). Returns: boolean — true if main process.
isForkedChild()
Description: Whether this is a Node child process created via child_process.fork (ELECTRON_RUN_AS_NODE === 1). Returns: boolean — true if forked child process.
processType()
Description: Get the current process type string. Returns: string — 'browser', 'renderer', or 'child'. Empty string if none match.
appName()
Description: Get the application name from EE_APP_NAME. Returns: string — application name, or empty string if not set.
appVersion()
Description: Get the application version from EE_APP_VERSION. Returns: string — application version, or empty string if not set.
getDataDir()
Description: Get the data storage path. In dev mode: {baseDir}/data. In production: {userHome}/.{appName}/data. On OpenHarmony: uses custom app directory for permission compatibility. Returns: string — absolute data directory path.
getLogDir()
Description: Get the log storage path. In dev mode: {baseDir}/logs. In production: {userHome}/.{appName}/logs. On OpenHarmony: uses custom app directory for permission compatibility. Returns: string — absolute log directory path.
getBundleDir(basePath?)
Description: Get the build output directory. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| basePath | string | No | Base path, defaults to process.cwd() |
Returns: string — {basePath}/public/electron.
getElectronCodeDir(basePath?)
Description: Get the electron source directory. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| basePath | string | No | Base path, defaults to process.cwd() |
Returns: string — {basePath}/electron.
getFrontendCodeDir(basePath?)
Description: Get the frontend source directory. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| basePath | string | No | Base path, defaults to process.cwd() |
Returns: string — {basePath}/frontend.
getRootDir()
Description: Get the root directory. In dev mode: project root (baseDir). In production: app user data directory. Returns: string — absolute root directory path.
getBaseDir()
Description: Get the project root directory (EE_BASE_DIR). Returns: string — project root directory, or empty string if not set.
getElectronDir()
Description: Get the electron directory where business code resides (EE_ELECTRON_DIR). Returns: string — electron directory path, or empty string if not set.
getPublicDir()
Description: Get the public static assets directory. Returns: string — {baseDir}/public.
getExtraResourcesDir()
Description: Get the extra resources directory. Path differs by platform after packaging:
- Windows/Linux:
{execDir}/resources/extraResources - macOS:
{execDir}/../Resources/extraResources - OpenHarmony:
{execDir}/../Resources/extraResources
Before packaging: {execDir}/build/extraResources. Returns: string — absolute extra resources directory path.
getAppUserDataDir()
Description: Get the Electron appUserData directory (EE_APP_USER_DATA). Returns: string — app user data directory, or empty string if not set.
getExecDir()
Description: Get the executable directory (EE_EXEC_DIR). After packaging, this is where the exe/dmg/deb is located. Returns: string — executable directory path, or empty string if not set.
getUserHomeDir()
Description: Get the OS user home directory (EE_USER_HOME). On OpenHarmony: returns appUserData directory for permission compatibility. Returns: string — user home directory path, or empty string if not set.
getUserHomeHiddenAppDir()
Description: Get the hidden app directory under the user home directory. Used for storing data, logs, and other persistent files in production. Returns: string — {userHome}/.{appName}/.
getUserHomeAppDir()
Description: Get the app directory under the user home directory (not hidden). Returns: string — {userHome}/{appName}/.
getAppCustomDataDir()
Description: Get the application custom data directory. Used on OpenHarmony where the user home directory is not writable. Returns: string — {appUserData}/{appName}/.
getSocketPort()
Description: Get the built-in Socket server port number. Returns: number — Socket server port, or 0 if not set. See also: socket module — SocketServer sets this port during initialization.
getHttpPort()
Description: Get the built-in HTTP server port number. Returns: number — HTTP server port, or 0 if not set. See also: socket module — HttpServer sets this port during initialization.
isPackaged()
Description: Whether the app is packaged (production environment, EE_IS_PACKAGED === 'true'). Returns: boolean — true if the app is packaged.
exit(code?)
Description: Exit the current process. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | number | No | Exit code, defaults to 0 |
Returns: never — this function never returns (terminates the process). Example:
import { exit } from 'ee-core/ps';
exit(1); // exit with code 1exitChildJob(code?)
Description: Exit a ChildJob-type child process. Checks process.argv[2] to determine if this is a ChildJob process. Only ChildJob processes will exit; other types of child processes are not affected. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | number | No | Exit code, defaults to 0 |
Returns: voidSee also: jobs module — ChildJob processes set type: 'childJob' in argv. Example:
import { exitChildJob } from 'ee-core/ps';
exitChildJob(); // only exits if current process is a ChildJobisChildJob()
Description: Determine whether the current process is of ChildJob type. Checks the type field in process.argv[2]. Returns: boolean — true if the current process is a ChildJob. See also: jobs module — ChildJob.
isChildPoolJob()
Description: Determine whether the current process is of ChildPoolJob type. Checks the type field in process.argv[2]. Returns: boolean — true if the current process is a ChildPoolJob. See also: jobs module — ChildPoolJob, LoadBalancer.
getArgumentByName(name, args?)
Description: Get the value of a named argument from command line arguments. Search format: --name=value. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Argument name (without the -- prefix) |
| args | string[] | No | Arguments array, defaults to process.argv |
Returns: string | undefined — argument value, or undefined if not found. Example:
import { getArgumentByName } from 'ee-core/ps';
// If process.argv contains '--env=prod'
const envValue = getArgumentByName('env'); // 'prod'makeMessage(msg?)
Description: Format an IPC message object, filling in missing fields with default values. Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| msg | Partial<{ channel: string; event: string; data: unknown }> | No | Partial message fields |
Returns: { channel: string; event: string; data: unknown } — complete message object with defaults (channel: '', event: '', data: {}).
