Live data from Hacker News

How to write a command line application in Node.js

blog.liangzan.net

1–10 of 56 posts

Re: How to write a command line application in Node.js

#3
post #2

Is there a reason to build a command line application in Node.js? It doesn't really seem like Node is the right tool for the job...

It's fun, simple, fast, and has a good package manager. JS is a high level scripting language like python or ruby but gives significant speed benefits in a lot of cases (in particular, the startup time of CLI programs written in Ruby always bothers me).

If you want to write in C for performance reasons, go ahead. But if your other alternatives are Python or Ruby and you already know JS, give node a go -- it's pretty fun.

Re: How to write a command line application in Node.js

#4
post #2

Is there a reason to build a command line application in Node.js? It doesn't really seem like Node is the right tool for the job...

If you're doing crazy heavy processing or something, it's not the right tool. But you wouldn't do that in JS. You'd shell out or call something native.

Node is best used managing parallel streams of stuff. Perhaps surprisingly, a command line application is a great example of that.

I would much rather build a nontrivial command line app in node than in anything else. Try it, you'll see.

Re: How to write a command line application in Node.js

#5
post #2

Is there a reason to build a command line application in Node.js? It doesn't really seem like Node is the right tool for the job...

Yes.

If a person already knows JavaScript well, then it will be easier for them to write a CLI app/utility/script in JS than it would be to write a shell script.

Another reason to write in JS would be to gain code reuse. If the person has a web app that uses node, then they can share code between the web and CLI applications.

Re: How to write a command line application in Node.js

#6
post #4
post #2

Is there a reason to build a command line application in Node.js? It doesn't really seem like Node is the right tool for the job...

If you're doing crazy heavy processing or something, it's not the right tool. But you wouldn't do that in JS. You'd shell out or call something native. Node is best used managing parallel streams of stuff. Perhaps surprisingly, a command line application is a great example of that. I would much rather build a nontrivial command line app in node than in anything else. Try it, you'll see.

There are tons of better options to choose from. If you're not making a web UI, literally any choice is better than Javascript, unless that is the only language you know.

Re: How to write a command line application in Node.js

#8
The number one reason to write CLI apps in node is npm. npm gets package management right, preferring local dependencies to global ones - this means no worrying about what version of a library a user has in their global environment.

You also get to bring node's parallel io-centric patterns to your scripting. Need to download a bunch of files from a remote host, process them, and write them to disk? Go for it.

But take it with a grain of salt: it's very much a use-what-you-know kind of thing.

Post reply on HN