Skip to content

🐞Fix arguments passed to NodeJS#760

Merged
cowboyd merged 1 commit intov3from
v3-node-main-args
Aug 30, 2023
Merged

🐞Fix arguments passed to NodeJS#760
cowboyd merged 1 commit intov3from
v3-node-main-args

Conversation

@cowboyd
Copy link
Copy Markdown
Member

@cowboyd cowboyd commented Aug 30, 2023

Motivation

The process argument handling is different from Deno and NodeJS. The following script in Deno:

$ deno script.ts hello world

will set Deno.args to ["hello", "world"]. By contrast, the following in NodeJS:

$ node script.mjs hello world

will set process.argv to
["/path/to/node","/abs/path/to/script.mjs", "hello", "world"]

The NodeJS way is similar to the argv of a Bash script, but the Deno way is more practical.

Approach

This normalizes Node to behave like Deno, only passing the user arguments to the script. We can explore how to get the script name and the executable name later.

The process argument handling is different from Deno and
NodeJS. The following script in Deno:

``` shellsession
$ deno script.ts hello world
```

will set `Deno.args` to `["hello", "world"]`. By contrast, the
following in NodeJS:

``` shellsession
$ node script.mjs hello world
```

will set `process.argv` to
`["/path/to/node","/abs/path/to/script.mjs", "hello", "world"]`

The NodeJS way is similar to the argv of a `Bash` script, but the
Deno way is more practical.

This normalizes Node to behave like Deno, only passing the user
arguments to the script. We can explore how to get the script name and
the executable name later.
@cowboyd cowboyd requested review from jbolda, neurosnap and taras August 30, 2023 14:35
Copy link
Copy Markdown
Member

@taras taras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cowboyd cowboyd merged commit 2ba7ade into v3 Aug 30, 2023
@cowboyd cowboyd deleted the v3-node-main-args branch August 30, 2023 14:53
taras pushed a commit that referenced this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants