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.
However, today there is more diversity in the JavaScript developer community. For example, Yehuda Katz is both a server-side (Rails) team member and client-side (JQuery, Ember) developer. Also, system engineers have begun working in JS. The Meteor team is a good example of system engineers working on JS.
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.
If you need that, there are only a handful of choices and node is one of them.
I'm not really arguing against using JavaScript for command-line interfaces. I'd much rather see that than the same in PHP, and if the programmers don't know Perl, Python or Ruby, then why not? We're talking about an area where there are still way to many hacks that consist of badly written bash scripts with lots of inline sed and awk...
People don't use node for the Javascript. They use it for the modules, and node is the glue that coheres them (and does an admirable job at that).
When you're comparing writing a CLI app in node to writing it in something else, it's a world of difference, and that difference is npm. With good modules, writing a CLI app has little to do with Javascript -- you're more specifying config and flow by passing some options and streams around, and you're done.
CPAN modules must provide POD documentation, must provide a regression test, and must run on several dozen platforms before PAUSE accepts to publish it on CPAN.
Python or Ruby modules, or my favorite Lua, are a bunch of junk compared to CPAN.
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.
> 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.
I often see this argument presented for just about any server side js. I often wonder about actual real world reuse though.I wrote a database specifically for web browsers and someone case along and write a relatively small pull request and it now works in node / on the server / with a http api - http://pouchdb.com
I share code between the client and server. For example, I have data type checks where I reuse the same library and the same application specific code on both the client and server.
I expose substantial portions of my server-side code via the command line. I also frequently call shell scripts from node as there are certain things I find easier to write in a shell script.
That said, I don't know if this amount of reuse is typical. And, code reuse is clearly not the only consideration.
For raw access to your MySQL database, the gem 'mysql2' is preferred (github with a simple tutorial: https://github.com/brianmario/mysql2).
mysql2 seems to have taken it's interface design from Perl's DBI, which is cool if you're used to that but might feel a little foreign.
If you'd like something that gives you a little more help, or there's substantial business logic in your script, take a look at ActiveRecord. This StackOverflow question (http://stackoverflow.com/questions/16683903/sinatra-mysql-an...) has a nice example of how you might set up your script to use AR.
My email's in my profile if you'd like any future help.
imho, node as command line makes even less sense then Smalltalk, Java or Mono. Those are heavy weight languages that have no place in interactive commandline scripting.
Better choices are the classical languages like Perl or Python, and Lua or awk has even less startup costs.
It's fast enough, and low-overhead enough, that I don't notice any overhead when running my Node.js build scripts. And really, that's all that matters.
Out of curiosity, I wrote a little script to test it:
#!/usr/local/bin/node
console.log(process.memoryUsage());
And here's the output (memory usage is in bytes): jshore$ time ./deleteme.js
{ rss: 12660736, heapTotal: 4083456, heapUsed: 2131864 }
real 0m0.055s
user 0m0.043s
sys 0m0.011sEDIT: Ok, just went through the nodejs api, they have cover a lot of ground now :)