
How to write a command line application in Node.js - dpmehta02
http://blog.liangzan.net/blog/2012/07/30/how-to-write-a-command-line-application-in-node-dot-js/
======
jasondenizac
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.

~~~
FooBarWidget
I thought a lot of people discourage the use of static linking or any form of
local dependency bundling, because when there's a security update every app
needs to be updated individually. But it seems that with the emergence of
Bundler and NPM, people are trending more and more towards local bundling.
What happened?

~~~
CamperBob2
One possible contrarian view: global dependencies actually _cause_ a lot of
those security updates to be necessary. Exploits that target a given version
of a given library may be easier to propagate if you know that almost every
application run by every user depends on that library version.

------
qrohlf
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...

~~~
rgbrgb
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.

~~~
retr0h
This is what happens when you let front-end developers loose in your
infrastructure.

~~~
gcr
Don't knock it 'till you try it. Most developers would balk at the idea of
creating a project in something that isn't their favorite language, especially
when they've been burned by poor uses of that language before.

~~~
retr0h
I have written plenty of JS, and absolutely hate it.

------
meandave
This was also recently released.
[https://github.com/chjj/blessed](https://github.com/chjj/blessed)

------
clarle
Definitely check out Inquirer.js if you're using prompts in a Node CLI
application. It's the prompt utility used by Yeoman generators:

[https://github.com/SBoudrias/Inquirer.js](https://github.com/SBoudrias/Inquirer.js)

------
olegp
Callbacks and CLI apps aren't a good fit in my opinion. I do like writing
command line tools using Common Node though: [https://github.com/olegp/common-
node](https://github.com/olegp/common-node)

------
logn
Or you could just use [http://silkjs.net](http://silkjs.net)

------
petercooper
Something similar but published just last week:
[http://flippinawesome.org/2013/07/29/writing-a-command-
line-...](http://flippinawesome.org/2013/07/29/writing-a-command-line-utility-
using-node/)

------
rtsuk
I find the lack of a synchronous way to pass a command to the shell and get
the result makes node much more difficult for the kinds of things I usual
write in ruby.

------
oscargrouch
in this day and age, if i had to create a command line app, from zero, i would
definetly start with go.. it has all the functionality in standard libs and
the package manager can handle github repos for third-parties (like mongo or
mysql drivers).. you just compile it and go!

can be as simple than that? the right tool for the job..

if i would create a library that everyone could use and embed i would use C
for that..

if i would like to build a VM, a compiler, a browser or a OS i would use c++
(is almost c, fast and gives you easy composability and control)

i would use javascript.. but only in the browser and because and dont have
nowhere to go or to runaway for.. (no transpiling either please)

this is just the general experience of my years of coding and deling with
every lang in the earth.. rsrs

ruby is pretty, eyecandy, bu is like a virgen that cant be touched.. python
looks just like perl.. is a complete mess, and is like the mafia,i prefer not
to touch or to have any involvement with them.. java is the frankenstein child
of c++.. you can create big software with it.. but to many keywords and
excessive use of vtables..

and for ui and web, network, etc.. i would use something like dart for this
job, any day.. the code can grow and you can still understand your code

so these days i would use c, c++, go or dart.. in the case i can choose of
course.. :)

~~~
siddboots
In this day and age, drumming off single-sentence dismissals of major
languages does not lend one much credibility.

The diversity of programming languages is due in part to the fact that
developers _enjoy_ looking at old problems from new angles. Doing so lets us
to make creative re-use of libraries and practices that were invented to solve
disparate problems, and good things invariably result.

Node.js is a staggering example, but every language you mentioned has its
strengths.

~~~
oscargrouch
im completelly aware that this is very subjective matter, and by saying
touching language options, a lot of people would get offended..

experimentation is good! it make us have more of the good ideas.. sure! go and
create a command line application in node.. nobody will forbid you to do that,
its not a sin..

i would do it.. but theres a difference between whats fun and what works.. one
thing i take my hat of for all dinamic languages like ruby, javascript and
even python, is that they want to make the experience of creating software
fun, and more pleaseant.. this is cool

but the answer its in the balance, thats something i respect about go and
dart.. the idea to mix fun and pragmatism so we can have both.. maybe better
things can come in the future.. and we should all thank dinamic language for
that..

javascript did not achieve the nirvana yet.. its like a duck.. it can walk?
sure. it can fly? sure. it can swim? yes.. but can do it good any of those
things? nop

------
vehementi
Bunch of broken URLs due to closing parentheses

------
dpweb
github.com/dpweb/cli-node

