The previous answer is not such a bad idea for a module (allocating ES6 files in the exec / child process), if you can deal with the idea of running it in a child process.
The best apparent answer is if you are a module, a document for which these functions are required, and check them at runtime and pledge with a useful error. I myself didn’t understand exactly how good it is to check (give me a break, I used node for 3 days)
If you are writing an application, the answer is slightly different. In my case, the application I'm writing will most likely use these functions - and due to the limited ability to use only one parameter in the shebang line, not being able to change the JS version at runtime (which of course, as explained above, makes sense ) and does not want to execute the child process (my server is already multithreaded) - I was forced to write a script to start my node server so that my users would not write, t need to find out the correct node communication line to start my application (ugly), and if I I will ever want to use more than --harmony and "use strict"; I can do this with a script, since it is just a shell script that calls node and my application.
It is recommended that you use #!/usr/bin/env node as a shebang (which will find the node for you wherever it is installed), however you can only use one option in shebang, so this will not work with --harmony (or any another parameter)
Of course, you can always run node --harmony --use_strict --blah_blah yourScript.js , but if you need certain parameters, you will have to type them every time, so it is recommended to use a shell script (from me!). I suppose you could include this (or such) script in your module and recommend using it when running an application using your module.
This is a similar implementation for a shell script that I use for my server, it will find node and run your script with any parameters you need:
#!/bin/bash if [ "$myScript" == "" ]; then myScript="./src/myNodeServer.js" fi if [ "$myNodeParameters" == "" ]; then myNodeParameters="--harmony --use_strict" fi if [ "$myNode" = "" ]; then myNode=`which node` fi if [ "$myNode" = "" ]; then echo node was not found! this app requires nodeJS to be installed in order to run. echo if you have nodeJS installed but is not found, please make sure the 'which' echo command is available. alternatively, you can forcibly specify the location of echo node with the $myNode environment variable, or editing this file. else echo Yay! node binary was found at $myNode fi if [ "$1" = "start" ]; then echo you asked to start.. echo calling $myNode $myParameters $myScript $2 $myNode $myParameters $myScript $2 exit elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo you asked for help.. echo usage: echo $0 start [script.js] [parameters for script] echo parameters for node and node location can be echo set with the \$myParameters and \$myNode env echo variables (or edit the top of this file). exit else echo no valid command specified - use $0 --help to see help. fi
It is worth noting that if you ONLY want to use harmony and strict, while you cannot specify both in shebang, you can rigidly specify the location of the node and use "use strict"; nickname:
#!/usr/bin/node --harmony "use strict";