39

It seems to me it would be very useful to use Javascript for general server side scripting tasks as it has more or less the same features as Perl and Python. But AFAIK there are no generally available Javascript interpreters for the major machine architectures. I guess the other problem may be lack of libraries but surely these would come if the interpreters were there. Google's V8 maybe could be a starting point. Does anyone think we'll see this soon?

3
  • 1
    And by the way: almost no one "interprets" JavaScript these days, pretty much all browsers compile it into native code just in time. Aug 27, 2012 at 7:27
  • 2
    In a sense there is an interpreter in Windows - see Jscript. It's not exactly Java Script, but it's close.
    – nhinkle
    Aug 28, 2012 at 3:44
  • 1
    Sounds of things indicate Windows 8 will have just that to some degree built in since you can build JS apps for native desktop use.
    – Rig
    Aug 28, 2012 at 12:52

5 Answers 5

68

Node.js is exactly what you're asking for ... and more.

In addition to being a JavaScript runtime it also provides APIs for common operations, such as file system access (JavaScript on the browser doesn't really need that) and network IO.

It's marketed for building network application (and it's great at that!), but it's really a general purpose JavaScript runtime that you can use to build anything you want. Also, it is based on V8.

5
  • 1
    Huh, yeah I only thought of node as for network apps as they are clear from their homepage on out that that's what it's for.
    – MebAlone
    Aug 27, 2012 at 7:40
  • 5
    @MebAlone: that's their main purpose, true. But node.exe (or just node on Unix-y platforms) is basically a simple JavaScript runtime. node myJavaScript.js runs myJavaScript.js and what more do you need from a runtime system? (Ok, you need debugging and libraries, but Node.js has those covered as well ;-)). A good indication for this is that many projects use JavaScript scripts (run in Node.js of course) as their build system. Aug 27, 2012 at 7:41
  • 1
    NodeJS runs on Google's V8. You can use V8 to do whatever you want. So even if NodeJS isn't a fit for you V8 might be. Aug 27, 2012 at 12:19
  • 2
    @Andrew: from what I know V8 doesn't ship any binaries, only source. So you'd have to build it yourself (or find third-party binaries). If you don't care about node, it's very easy to just ignore the libraries and use node as a pure JavaScript runtime. I don't see how you can do that with equal ease with V8. Aug 27, 2012 at 12:28
  • One example of a *non-*networked application in node would be the CoffeeScript module that can be run in command line to compile your coffeescript files to javascript.
    – Spoike
    Aug 27, 2012 at 12:43
77

As mentioned by Joachim, node.js is exactly what you ask for.

It appears to not be well known when compared with Python and especially Perl for this type of thing, but perhaps that is simply because JavaScript isn't widely considered to be very good.

enter image description here

7
  • 2
    The Good Parts make up for all the other things Javascript has going on... that and CoffeeScript. Oh CoffeeScript!
    – Spoike
    Aug 27, 2012 at 12:40
  • 4
    +1 for the Kinect on a stack of books. I have the definitive guide sitting under my monitor to raise the monitor height a little bit.
    – Phil
    Aug 27, 2012 at 13:35
  • 3
    -1, despite the funny photo, this answer is essentially a fancy way of saying 'cuz it sucks', and doesnt really contribute anything. Aug 27, 2012 at 18:13
  • 3
    No, that's not what he's saying at all.
    – Michael B
    Aug 27, 2012 at 19:06
  • 2
    Lol, The Definitive Guide - not a javascript book at all but one about web browser DOMs, with a little bit of js at the beginning.
    – gbjbaanb
    Aug 28, 2012 at 12:17
29

Windows Script Host has included a JScript (javascript) engine since at least Windows 2000 out of the box, allowing you to do sysadmin tasks using javascript.

http://en.wikipedia.org/wiki/Windows_Script_Host

It's also possible to embed this into a windows application using the WScript.Shell ActiveX/COM object.

2
  • ah, very cool !
    – MebAlone
    Aug 27, 2012 at 21:14
  • 3
    WSH also lets you use a number of other scripting languages (like vb); and if I'm not mistaken more can be installed (en.wikipedia.org/wiki/…). You can also use it to script other windows apps, like media player, word, etc.
    – frozenkoi
    Aug 27, 2012 at 22:18
6

In addition to node.js, there is also gjs, which is a GNOME-oriented runtime giving access to GNOME, GTK, and GLib libraries, among others. I believe you can use with it any library that supports GObject introspection.

Gjs is used widely in the GNOME3 desktop.

3

There is a javascript interpreter written for Java apps (called Rhino) and it seems to be designed to write server code in javascript, but have it execute as java code.

Personally, I think you're much better off with node.js as that is awesome. For a quick introduction, you can do much much worse than read the (free) NodeBeginner book.

2
  • For completeness' sake: Rhino does not make Javascript execute as Java code, it's a Javascript interpreter, i.e. it executes Javascript in a JVM environment. Of note is that it's not very fast, compared to more low-level interpreters like V8.
    – cthulhu
    Sep 9, 2012 at 12:50
  • good free book. Sep 15, 2013 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.