6 ms·
You are so right. When I saw the link I thought: "That could be fun, lets take a look how it displays the data". But when I saw that it uses node.js I thought "
by JepZ 9y ago
You are so right. When I saw the link I thought: "That could be fun, lets take a look how it displays the data". But when I saw that it uses node.js I thought "Oh my god, who had this brilliant idea to write it with node"...
Hey guys, please use rust, golang, haskell or whatever you like, but please do not use nodejs to write CLI tools.
And I am not one of the guys who is against JS in general. In fact, I like building PWAs and other JS heavy apps/websites a lot. But there are so many tools do a better job at building cli programs.
- Klathmon 9y agoI don't get the hate here, Node works great for CLI tools. Easy and quick install, supports colors and icons in the terminal, has several easy and useful table libraries to choose from, and it runs plenty fast enough for it's use case. What benefits would rust, golang, haskell, or whatever you like provide over node in this situation?
- drinchev 9y agoI'm quite confident that "whatever you like" does not benefit versus NodeJS anyway. And of course you should write cli tools with whatever you feel comfortable. If you want them to be well-received by everyone, well that's a different topic.
- diggan 9y agoAlso a NodeJS fan in general, but prefer to install/develop cli's with golang instead of node just because you get a compiled, static binary that works cross-platform. Faster for users to install, less bloaty and works on all platforms without any dependencies.
- 52-6F-62 9y agoI personally usually use Python, Bash, or C, but there is a utility for packaging NodeJS tools into executables. I think it does some tree-shaking as well. Disclaimer: I haven't used it, so I'm not sure of the results. But it is possible. https://www.npmjs.com/package/pkg https://www.npmjs.com/package/pkg edit: For the curious -- Just tried on a really simple script that just takes one argument and writes it with some text to STDOUT and it still came to 35MB. So it must package a bunch of Node with it. I won't be leaving my go-to's for it anytime soon unless usability and development speed necessitate it. Going to have to go with the, best to not use NodeJS for general cmd-line utils outside of the NodeJS environment. The one perk is that it will, by default, output executables for Linux, macOS, and Windows. Source: (function() { 'use strict'; function main(_string) { console.log(`${_string} was read from STDIN.`); } main(process.argv[2]); }()); Output file: 35088858 Nov 20 11:36 index-linux 35717043 Nov 20 11:36 index-macos 23137020 Nov 20 11:36 index-win.exe
- WildGreenLeave 9y agoThats because PKG is including the Node runtime in the binaries, this way users don't have to install Node itself to run them. I'm using it myself and besides the fat binaries and the fact that you have to write Javascript, it is really good. (Working on replacing this daemon with Go ASAP) Edit: just read your last line, I'm kinda stating the obvious here.
- JepZ 9y agoI wouldn't call it hate. It is more like 'wtf, please don't do that' ;-) Actually, you can write cli tools with js, it's just that in most cases it is not a good choice. There are some reasonable cli tools which can be written in js e.g. js dev-tools like rollup, gulp, grunt, etc. But I would not consider Coinmon a js dev-tool ;-) When you say 'Easy and quick install' thats not completely true. First of all it assumes that you have a js package manager installed already (npm/yarn), which is not preinstalled on most OS. So yes, nowadays thats not too much of a hassle. But from a package manager perspective npm itself is a disease as it does not integrate with the system package manager so your system is not completely up to date after you told your package manager to update all package. Instead you have to start npm to let it run its own updates. Sometimes even that is not as simple as it could be because frontend-devs tend to advise to install npm packages locally (within a project) instead of globally (once per system). I think we could continue this discussion for a while as there are many more arguments to be evaluated (not everything about npm is bad), but ultimately we will find out, that other languages would be a better fit for such tools. Again, my initial commment was meant as 'advice' and not as 'hate'. Yes I know, nobody asked for advice ;-)
- steveklabnik 9y agoNode is fine, and I don't agree with the hate, but Rust and Go would both give you a single binary that just runs everywhere. Not everyone already has Node installed.
- thinkxl 9y agoI get what adtac said, but, "not use node for cli tools?" Come on, so if I only know JavaScript and I want to build a cli tool for personal use that can later open source, shouldn't do it because the language? That's not the hacker mentality, you can write a cli tool with JavaScript, Python, Lua, etc., make it work and there's nothing wrong with it. If you want to go full deep into cli tooling, then you start to looking into other languages that can fit into your new requirements.
- bichenkk 9y agoThanks a lot for the comment. This is actually a practice work when I was reading this https://developer.atlassian.com/blog/2015/11/scripting-with-node/ https://developer.atlassian.com/blog/2015/11/scripting-with-... Which language (rust, golang, haskell) do you think it is more fitting? I am new to writing things running on command line @@