Skip to content

Commit 271bebd

Browse files
committed
src: .env file can override NODE_OPTIONS
1 parent edaa662 commit 271bebd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/node_dotenv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void Dotenv::SetEnvironment(node::Environment* env) {
5151

5252
auto existing = env->env_vars()->Get(key.data());
5353

54-
if (existing.IsNothing()) {
54+
if (existing.IsNothing() || strcmp(key.data(), "NODE_OPTIONS") == 0) {
5555
env->env_vars()->Set(
5656
isolate,
5757
v8::String::NewFromUtf8(

test/parallel/test-dotenv-edge-cases.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ describe('.env supports edge cases', () => {
4747
assert.strictEqual(child.stderr, '');
4848
assert.strictEqual(child.code, 0);
4949
});
50+
51+
it('should override NODE_OPTIONS', async () => {
52+
const code = `
53+
require('assert').strictEqual(process.env.NODE_OPTIONS, '--experimental-permission --allow-fs-read=*');
54+
`.trim();
55+
const child = await common.spawnPromisified(
56+
process.execPath,
57+
[ `--env-file=${relativePath}`, '--eval', code ],
58+
{ cwd: __dirname, env: { NODE_OPTIONS: '--experimental-permission --allow-worker' } },
59+
);
60+
assert.strictEqual(child.stderr, '');
61+
assert.strictEqual(child.code, 0);
62+
});
5063
});

0 commit comments

Comments
 (0)