31

Recently I've fallen out of love with Perl as a cross-platform general purpose scripting language, and niether Python nor Ruby ever really appealed to me either.

But I've been getting more and more comfortable with JavaScript in the browser, it's getting pretty good performance in contemporary engines such as V8, and node.js has been really taking off for a couple of years now.

But node.js is intended for server side networking programming primarily. As it declares itself on its homepage:

Event-driven I/O server-side JavaScript environment based on V8.

I would like to know if node.js is also currently suitable as a general scripting language on *nix and Windows as an alternative to Perl, Python, and Ruby.

I don't find much talk of it being used in this way yet it does seem to have a broad community and I haven't noticed anything saying it's not suitable for this use. Is it widely used this way? Or does it lack key features or modules for this type of thing?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
  • 2
    A lot of JavaScript tools run on top of node.js, not just server-ish things. – mu is too short Dec 16 '12 at 08:12
  • Really? any pointers. I have looked as I said: `I don't find much talk of it being used in this way` – hippietrail Dec 16 '12 at 08:15
  • 2
    Coffeescript compiler, or npm are popular examples. – Thilo Dec 16 '12 at 08:15
  • Thanks Thilo. Those aren't necessarily the kinds of everyday scripting tasks Perl and Python have been used for though. For example asking my question as a Google search doesn't turn up any useful leads I can see: http://goo.gl/neYds Also questions about these kinds of uses here on SO just don't seem to come up yet, or not enough to notice... – hippietrail Dec 16 '12 at 08:17
  • 1
    best thing to do is give it a try and decide for yourself. – chovy Dec 16 '12 at 08:49
  • I am not sure the term/question "...if node.js is also currently suitable as a general scripting language..." is correct, because nodejs is kind of server, that runs JavaScript as scripting language, so the real question is "if JavaScript is also currently suitable as a general scripting language". That means that if you are comfortable with JavaScript - this may work for you. – Michael Vashchinsky Dec 16 '12 at 10:26
  • Well now I can ask a new question about any other JavaScript implementations for general purpose scripting and reference this question. Thanks for your input everybody. I'm certainly going to give node.js a shot but it looks like many basic things are missing such as formatted output. – hippietrail Dec 16 '12 at 23:25
  • Apparently this question is not constructive. I think it is constructive to say: • One example of a feature preventing node.js from taking the place of Perl and Python is the lack of a built-in function to read one line from a text file. • One feature of node.js that makes it better than Perl and Python is that it supports Unicode in the console out of the box on both *nix and Windows platforms. (I welcome suggestions for questions that wouldn't be considered counterproductive that could bring up points like these...) – hippietrail Jan 03 '13 at 08:21
  • Why have you fallen out of love with Perl – vol7ron Jul 24 '13 at 15:32

1 Answers1

31

In terms of Node.js, I can't see it becoming a mainstream way of using javascript as a general purpose scripting language. The main reason for that would be the async nature of 99% of the libraries and functions available in Node.js. Because of the async nature, you have to completely change your thinking. Not having synchronous methods available is the stumbling block. It makes things less script like as your code is not linear anymore.

So the adoption is not happening for the simple reason that most of the time you're thinking: I could write this a lot quicker/simpler in Ruby/Python/... (just try downloading 5 different files, zipping them and copying them to another folder using Node.js)

As people get more used to thinking and programming in an async way adoption of node.js as a general purpose scripting tool might change.

If every async function in node had a synchronous version, adoption would have been different and people would have ended up with non scalable node.js servers because they choose to use sync methods in places. Arguably, node would not have become popular as the performance numbers wouldn't have made it stand out.

In short:

adoption of node.js is happening because of it's async nature. adoption of node.js as a client side general purpose scripting tool is not happening due it's lack of synchronous functions.

Please keep in mind that this is based on my own experience and opinion and not on articles or numbers I found on the internet so try it out for yourself and make up your own opinion.

AndyD
  • 5,252
  • 35
  • 32
  • 2
    It should be noted that "will node.js be mainstream" and "is node.js usable as a general programming language" are two separate questions. Though they sometimes are related if you care about being able to hire developers or other people reading your code. – slebetman Dec 16 '12 at 13:01
  • agreed. It's very easy to get carried away with various new tools and technologies, but forgetting that you are tying yourself/your company to that technology. Your code can affect future HR decisions! :) – AndyD Dec 16 '12 at 14:44
  • Thanks for the answer @AndyD - for me the asynchronous nature was part of its appeal even for general purpose scripting, but I could be missing something having not experimented with it yet. – hippietrail Dec 16 '12 at 23:26
  • 1
    ALL node.js filesystem functions have sync alternatives in the 'fs' module. – Shivanshu Goyal Jan 10 '15 at 03:02
  • 1
    True, but things like http.request and child_process.exec do not (though this can be mitigated with dependencies like https://www.npmjs.com/package/exec-sync) – rich remer Jan 29 '15 at 15:53
  • is it still valid? I guess it requires major changes. – M at Feb 23 '23 at 17:46