I need to set an environment variable from Node (currently using v8.9.3)
Ideally, I would like to run export DATA_DIR=/var/lib/data when the program starts.
1. Tried spawning a child_process to set this, but it does not appear to work.
Example:
const { spawnSync } = require( 'child_process' );
spawnSync( 'export', [ 'DATA_DIR=/var/lib/data' ] );
But this results with an ENOENT:
Error: spawnSync export ENOENT...
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawnSync export',
path: 'export',
spawnargs: [ 'DATA_DIR=/var/lib/data' ]
2. Tried setting process.env.DATA_DIR = '/var/lib/data' but this appears to be local to the node process and is not recognized by others.
3. Tried npm modules: dotenv,