Live data from Hacker News

How to write a command line application in Node.js

blog.liangzan.net

51–56 of 56 posts

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

#51

Earlier quoted context omitted.

Isn't Ruby just 'gem install mysql'?

I don't recall the instructions I looked at, but I know what I read was much more than a gem install. Correct me if I'm wrong, I actually wanted to use Ruby first.

Sorry if this is off topic, but I remember having this exact issue when I was learning Ruby, maybe I can provide some clarity.

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.

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

#52
post #28
post #26

Earlier quoted context omitted.

Hahaha really? Have you seen a pom file on a real project its about 10 pages with plugins galore.

really. if a page is about 60-80 lines, that's what, 1000 lines? and most IDE's help manage them. The makefile's to some open source projects get longer than that, and they only get worse when they're proprietary.

I didn't know that the bar is makefiles... welcome to 1977.

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

#53

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

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…

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

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

#54
post #49
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...

What is the memory footprint of node? What is the startup cost? 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.

> What is the memory footprint of node? What is the startup cost?

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.011s

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

#55
post #32
post #12

Earlier quoted context omitted.

Compared to most languages you'd use for a commandline application, node has a simple, usable async I/O interface, and the libraries you can get for it actually assume async. If you need that, there are only a handful of choices and node is one of them.

Which scripting language doesn't have an async library available (most of which don't descend into the Chinese Hell of Being Called Back Ad Infinitum)? Granted, most of the other languages have lots of libraries that don't play well with async, but then again, that's mostly because they have lots of libraries . And it's not like there's a guarantee that a random Node package won't screw you up, either. I'm not really…

concurrency != async

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

#56
post #51

Earlier quoted context omitted.

I don't recall the instructions I looked at, but I know what I read was much more than a gem install. Correct me if I'm wrong, I actually wanted to use Ruby first.

Sorry if this is off topic, but I remember having this exact issue when I was learning Ruby, maybe I can provide some clarity. 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 so…

Thanks. Appreciate the info.
Post reply on HN