Node: Disable/Hide all command line options?

Created on 12 Jan 2017  路  5Comments  路  Source: nodejs/node

Is there a way to compile Node.JS with having command line options disabled? I am using custom builds (with all included) and I have my own command line parser (yargs) but it collides with the built-in command line arguments.

Currently I have to add a "noob" command:
mynode.exe noob --non-node-js-option=foo // this works so far but I am never able to output my own help:

mynode.exe noob --help

I already tried shifting argv but its not really what I want: disable the built-in args altogether.

thanks,
g

question

Most helpful comment

No built in way.

Node.js parses arguments in ParseArgs in src/node.cc, which is called from Init in src/node.cc.

An alternative suggestion is to build Node.js as a shared library (configure --shared) and invoke Node::Start from your own launcher (from which you can control the args passed into Node::Start).

All 5 comments

Why do you think you need to disable the arguments for?

You can simply make your js file executable:

$ > chmod +x myfile.js

And then simply call it like:

$ > ./myfile.js --option-1 --option-2

Your file contents should be like:

#!/usr/bin/env node

var args = process.env.argv.slice(2);

console.log(args);

Then you will get the arguments passed to your script.

Hi @dkfiresky

thanks for the heads up. I am not sure you understood this right:

I want to compile Node.JS to my_custom_server.exe with all my sources included (I got this done) but disable the built-in command-line args entirely for a number of reasons, eg: --help is caught by my application but I also would like to hide everything which could indicate its a Node.JS app. Also, I have apps which should not return anything on --help.

Looking at the c++ source code, it seems rather difficult, or at least a longer story.

I am not sure how this fits to Node.JS's goals but: tricks like argv.slice as well exposing security sensitive information about my binaries are not really my cup of tea.

Anyhow, close this is here just ifits out of your scope, I am ok with hacks (pretty annoying over time)

No built in way.

Node.js parses arguments in ParseArgs in src/node.cc, which is called from Init in src/node.cc.

An alternative suggestion is to build Node.js as a shared library (configure --shared) and invoke Node::Start from your own launcher (from which you can control the args passed into Node::Start).

@richardlau : excellent, thanks for the pointer! Despite there is a way (not that pleasant in reality), you can close this if you like. To me it rather seems that this should be a build option/flag.

greets!

I'll close this then, feel free to continue the discussion here!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenvachon picture stevenvachon  路  3Comments

srl295 picture srl295  路  3Comments

jmichae3 picture jmichae3  路  3Comments

addaleax picture addaleax  路  3Comments

willnwhite picture willnwhite  路  3Comments