2

I prefer ES6 syntax and has grown quite used to the syntax, however, when developing CLI in node.js that is meant for public consumption (even non-javascript devs), should I always fall back to code that is compatible with really old version of Node.JS, say 0.6 as I can not be sure what Node.JS version a user has installed on his system.

What is a good and/or common practice to ensure maximum compatibility with users who may not necessarily only consists of users familiar with Node.JS?

uzyn
  • 6,625
  • 5
  • 22
  • 41
  • 1
    Nope. Write ES 6+ code and compile it to ES 5 with [Babel](https://babeljs.io/). – Michał Perłakowski Aug 28 '16 at 16:56
  • I see that my question has been flagged as off-topic. I feel asking for best and/or common practice should not be off-topic and would be useful for many. – uzyn Aug 28 '16 at 17:03
  • Thanks @Gothdo so in a nutshell, distributed code should ideally be in ES5. What is the lowest Node.JS that I should be testing against? Any usage stats (like IE usage for web browsers). – uzyn Aug 28 '16 at 17:05
  • 1
    If your users are not familiar with JS, and you don't know which nodejs version they have installed (if at all), why not just [bundle the runtime with the code](http://stackoverflow.com/q/6145561/1048572) into an executable application? – Bergi Aug 28 '16 at 21:58
  • That's a great answer @Bergi Thanks! – uzyn Aug 29 '16 at 04:19

1 Answers1

0

So, this is more of an opinion question, so here's my opinion:

If you plan on distributing your CLI application via NPM, then you should make sure that your CLI runs on the current LTS version of Node. This means that at the time of this answer, you should support Node 4 / 5: https://github.com/nodejs/LTS

Now, ideally, for a CLI application, you would not distribute it via NPM. The reason here is that there are tons of people out there who might find your CLI useful, many of which are NOT node developers.

What I prefer to do is bundle up my CLI applications for distribution so that they contain Node in a sandboxed environment to run the CLI. This way: you can write your CLI and use whatever version of Node you want, and your user can install it without even needing to know what Node is.

rdegges
  • 32,786
  • 20
  • 85
  • 109
  • 2
    *"this is more of an opinion piece, but here's my opinion:"* So.... off-topic? ;) – Felix Kling Aug 28 '16 at 16:57
  • Good catch. Updated =) – rdegges Aug 28 '16 at 16:57
  • Thanks, even with LTS, I have a feeling many machines are still running old & obsolete Node.JS that came preinstalled. This kind of feels like an IE thing, except for Node.JS and worse as we are blind without analytics. BTW, any good bundler that you can recommend to wrap the CLI code? – uzyn Aug 28 '16 at 17:01