You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder if there is a better way to pass NODE_OPTIONS to node cli. It turned out we need in production custom memory settings or good defaults (lowering resource usage).
Is there something like .noderc, or interpretation of an environment variable like NODE_OPTIONS by the node executable to pass runtime options?
Some people reported that options are given by option mames with underscore e.g. --max_old_space_size=100 (Maybe on CentOS ...). How could I find out which naming scheme (dash vs. underscore) is used?
hey @megastef I help maintain canary in the gold mine, a cli + library for testing node packages. You might find some of the patterns we use in there useful
I want to give the user full control on node Options - /bin/env node might fail on ubuntu, the binary might be named 'nodejs'. My shebang line tries to catch this case. The second problem is that options might have underscore or dash (i assume this is a compile time config e.g on CentOS). Well, this migh be a fight with legacy node versions. Thx.
To answer let me explore the functionality of the shebang a little: The shebang is a reference to the application that launches the current script file. #!/bin/bash refers to a bash application. Interestingly - unlike bash - the node binary is not at the same place in every system. #!/usr/bin/env on the other hand is a binary on the same place and it knows how to start a local command so #!/usr/bin/env node passes in the argument node to env and env is so cool to start this for us.
Recap: #!<command> <args> is the signature of a shebang
It would be easy if you could just pass in the arguments like #!/usr/bin/env node $@ but a test.sh with this content: #!echo $@ will print $@ test.sh That means: the shebang can not take arguments from the command line
The only option to start node with dynamic arguments is to start it in a child process. Now: We could make this complicated and write it in a separate file or we could do something like this:
This way all the parameters are passed in to the node sub process. If you add some parameter check's to the bash script you could even decide which node parameters are okay to pass-in and which are not.
If you can tell env to use an alias of node instead of node, then you are all setup already! Unfortunately I have not yet figured out how. more here
Hi @martinheidegger, long time not seen :)
My shebang line works fine. Setting memory default, detecting node binary name, and taking custom NODE_OPTIONS.
Actually I had the hope that the Node.js binary could take options from an (undocumented?) environment variable or resource file. But it looks we have to live with shell tricks to inject this parameters.
I think it would be a good feature for node to respect e.g. NODE_OPTIONS environment variable.
would result in $FOO test.sh when called using env FOO=bar. As such I assume that you can't simply pass in environment variables as NODE_OPTIONS would not do much help in the shebang.
I also think that it might be a bad idea to have this option in a file since the properties would apply to any node process running. I kind-of still think that the current way to do it seems right.
Activity
megastef commentedon Mar 31, 2016
Should i open an issue in node/node repository?
MylesBorins commentedon Mar 31, 2016
hey @megastef I help maintain canary in the gold mine, a cli + library for testing node packages. You might find some of the patterns we use in there useful
https://github.com/nodejs/citgm/
I'm not 100% I'm following what you shebang logic is doing, but I usually start a bin with
#!/usr/bin/env nodeas you can see here https://github.com/nodejs/citgm/blob/master/bin/citgm#L1If you want to include arguments to node you can just append them on that line
in your case
This was the correct place to ask the question, thanks for your patience!
megastef commentedon Mar 31, 2016
I want to give the user full control on node Options - /bin/env node might fail on ubuntu, the binary might be named 'nodejs'. My shebang line tries to catch this case. The second problem is that options might have underscore or dash (i assume this is a compile time config e.g on CentOS). Well, this migh be a fight with legacy node versions. Thx.
martinheidegger commentedon Mar 31, 2016
To answer let me explore the functionality of the shebang a little: The shebang is a reference to the application that launches the current script file.
#!/bin/bashrefers to a bash application. Interestingly - unlikebash- the node binary is not at the same place in every system.#!/usr/bin/envon the other hand is a binary on the same place and it knows how to start a local command so#!/usr/bin/env nodepasses in the argumentnodetoenvandenvis so cool to start this for us.Recap:
#!<command> <args>is the signature of a shebangIt would be easy if you could just pass in the arguments like
#!/usr/bin/env node $@but atest.shwith this content:#!echo $@will print$@ test.shThat means: the shebang can not take arguments from the command lineThe only option to start node with dynamic arguments is to start it in a child process. Now: We could make this complicated and write it in a separate file or we could do something like this:
This way all the parameters are passed in to the node sub process. If you add some parameter check's to the bash script you could even decide which node parameters are okay to pass-in and which are not.
If you can tell
envto use an alias of node instead of node, then you are all setup already! Unfortunately I have not yet figured out how. more heremegastef commentedon Mar 31, 2016
Hi @martinheidegger, long time not seen :)
My shebang line works fine. Setting memory default, detecting node binary name, and taking custom NODE_OPTIONS.
Actually I had the hope that the Node.js binary could take options from an (undocumented?) environment variable or resource file. But it looks we have to live with shell tricks to inject this parameters.
I think it would be a good feature for node to respect e.g. NODE_OPTIONS environment variable.
martinheidegger commentedon Mar 31, 2016
A
test.shscript with the shebang#!echo $FOOwould result in
$FOO test.shwhen called usingenv FOO=bar. As such I assume that you can't simply pass in environment variables asNODE_OPTIONSwould not do much help in the shebang.I also think that it might be a bad idea to have this option in a file since the properties would apply to any node process running. I kind-of still think that the current way to do it seems right.