process: save original argv[0] · nodejs/node@a804db1

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -457,9 +457,10 @@ added: v0.1.27

457457
458458

The `process.argv` property returns an array containing the command line

459459

arguments passed when the Node.js process was launched. The first element will

460-

be [`process.execPath`]. The second element will be the path to the

461-

JavaScript file being executed. The remaining elements will be any additional

462-

command line arguments.

460+

be [`process.execPath`]. See `process.argv0` if access to the original value of

461+

`argv[0]` is needed. The second element will be the path to the JavaScript

462+

file being executed. The remaining elements will be any additional command line

463+

arguments.

463464
464465

For example, assuming the following script for `process-args.js`:

465466

@@ -486,6 +487,22 @@ Would generate the output:

486487

4: four

487488

```

488489
490+

## process.argv0

491+

<!-- YAML

492+

added: REPLACEME

493+

-->

494+
495+

The `process.argv0` property stores a read-only copy of the original value of

496+

`argv[0]` passed when Node.js starts.

497+
498+

```js

499+

$ bash -c 'exec -a customArgv0 ./node'

500+

> process.argv[0]

501+

'/Volumes/code/external/node/out/Release/node'

502+

> process.argv0

503+

'customArgv0'

504+

```

505+
489506

## process.chdir(directory)

490507

<!-- YAML

491508

added: v0.1.17

Original file line numberDiff line numberDiff line change

@@ -50,6 +50,11 @@

5050
5151

_process.setupRawDebug();

5252
53+

Object.defineProperty(process, 'argv0', {

54+

enumerable: true,

55+

configurable: false,

56+

value: process.argv[0]

57+

});

5358

process.argv[0] = process.execPath;

5459
5560

// There are various modes that Node can run in. The most common two