electron/docs/api/environment-variables.md
Shelley Vohr 83124889e5
feat: enable passing Node.js cli flags (#21110)
* feat: enable passing Node.js cli flags

* Allow cli flags in ELECTRON_RUN_AS_NODE mode
2020-02-07 02:59:38 +00:00

149 lines
4.1 KiB
Markdown

# Environment Variables
> Control application configuration and behavior without changing code.
Certain Electron behaviors are controlled by environment variables because they
are initialized earlier than the command line flags and the app's code.
POSIX shell example:
```sh
$ export ELECTRON_ENABLE_LOGGING=true
$ electron
```
Windows console example:
```powershell
> set ELECTRON_ENABLE_LOGGING=true
> electron
```
## Production Variables
The following environment variables are intended primarily for use at runtime
in packaged Electron applications.
### `NODE_OPTIONS`
Electron includes support for a subset of Node's [`NODE_OPTIONS`](https://nodejs.org/api/cli.html#cli_node_options_options). The majority are supported with the exception of those which conflict with Chromium's use of BoringSSL.
Example:
```sh
export NODE_OPTIONS="--no-warnings --max-old-space-size=2048"
```
Unsupported options are:
```sh
--use-bundled-ca
--force-fips
--enable-fips
--openssl-config
--use-openssl-ca
```
`NODE_OPTIONS` are explicitly disallowed in packaged apps, except for the following:
```sh
--max-http-header-size
--http-parser
```
### `GOOGLE_API_KEY`
Geolocation support in Electron requires the use of Google Cloud Platform's
geolocation webservice. To enable this feature, acquire a
[Google API key](https://developers.google.com/maps/documentation/geolocation/get-api-key)
and place the following code in your main process file, before opening any
browser windows that will make geolocation requests:
```javascript
process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE'
```
By default, a newly generated Google API key may not be allowed to make geolocation requests.
To enable the geolocation webservice for your project, enable it through the
[API library](https://console.cloud.google.com/apis/library).
N.B. You will need to add a
[Billing Account](https://cloud.google.com/billing/docs/how-to/payment-methods#add_a_payment_method)
to the project associated to the API key for the geolocation webservice to work.
### `ELECTRON_NO_ASAR`
Disables ASAR support. This variable is only supported in forked child processes
and spawned child processes that set `ELECTRON_RUN_AS_NODE`.
### `ELECTRON_RUN_AS_NODE`
Starts the process as a normal Node.js process.
In this mode, you will be able to pass [cli options](https://nodejs.org/api/cli.html) to Node.js as
you would when running the normal Node.js executable, with the exception of the following flags:
* "--openssl-config"
* "--use-bundled-ca"
* "--use-openssl-ca",
* "--force-fips"
* "--enable-fips"
These flags are disabled owing to the fact that Electron uses BoringSSL instead of OpenSSL when building Node.js'
`crypto` module, and so will not work as designed.
### `ELECTRON_NO_ATTACH_CONSOLE` _Windows_
Don't attach to the current console session.
### `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_
Don't use the global menu bar on Linux.
### `ELECTRON_TRASH` _Linux_
Set the trash implementation on Linux. Default is `gio`.
Options:
* `gvfs-trash`
* `trash-cli`
* `kioclient5`
* `kioclient`
## Development Variables
The following environment variables are intended primarily for development and
debugging purposes.
### `ELECTRON_ENABLE_LOGGING`
Prints Chrome's internal logging to the console.
### `ELECTRON_LOG_ASAR_READS`
When Electron reads from an ASAR file, log the read offset and file path to
the system `tmpdir`. The resulting file can be provided to the ASAR module
to optimize file ordering.
### `ELECTRON_ENABLE_STACK_DUMPING`
Prints the stack trace to the console when Electron crashes.
This environment variable will not work if the `crashReporter` is started.
### `ELECTRON_DEFAULT_ERROR_MODE` _Windows_
Shows the Windows's crash dialog when Electron crashes.
This environment variable will not work if the `crashReporter` is started.
### `ELECTRON_OVERRIDE_DIST_PATH`
When running from the `electron` package, this variable tells
the `electron` command to use the specified build of Electron instead of
the one downloaded by `npm install`. Usage:
```sh
export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing
```