17

Is there a way one could run Javascript the way Python, Bash, Windows Batch or other scripting languages are run?

File access and other library functions would be nice but are not required - I'm just most fluent and most efficient in Javascript these days. Opening up a browser console each time is rather uncomfortable, though.

I'd be most interested in Windows environment.

1
  • 3
    Node.js is the most widely used, frequently maintained and most standard JavaScript shell you can find. It will allow you to run the latest JavaScript features.
    – ilgaar
    Jun 3, 2017 at 12:08

4 Answers 4

22

Is there a way to run JavaScript without a browser, like a shell or batch script?

What you are looking for are JavaScript shells.

A JavaScript shell allows you to quickly test snippets of JavaScript code without having to reload a web page. They are extremely useful for developing and debugging code.


Standalone JavaScript shells

The following JavaScript shells are stand-alone environments, like perl or python.

  • Node.js - Node.js is a platform for easily building fast, scalable network applications.
  • JSDB - A standalone JavaScript shell, with compiled binaries for Windows, Mac, and Linux.
  • JavaLikeScript - A standalone, extensible JavaScript shell including both native and JavaScript libraries.
  • GLUEscript - A standalone JavaScript shell for writing cross-platform JavaScript applications. It can use wxWidgets for GUI apps, and was formerly called wxJavaScript.
  • jspl - A standalone JavaScript shell enhanced by Perl. Can use perl modules directly from JavaScript: DBI for database integration, GTK2 for GUI apps, POSIX for system programming, etc. The best of CPAN now for JavaScript programmers.
  • ShellJS - Portable Unix shell commands for Node.js
  • Windows Script Host - Microsoft® Windows® Script Host (WSH) is a language-independent scripting host for Windows Script.

Source JavaScript shells

1
  • +1 Thank you, that's a very thorough answer! The jspl and GLUEScript look very interesting, that's exactly what I had in mind.
    – Pavel
    Jul 28, 2015 at 13:05
12

Node.js is what you're looking for.

It's based on V8, the same JavaScript engine that Chrome uses. You can use it as a REPL or run scripts from .js files.

Node.js's popularity in commercial projects is increasing recently. It's used for servers that have to handle many parallel connections. It's also used for development purposes, for example Bower (front-end development package manager) is written completely in JavaScript and intended to run on Node.js.

7

For the sake of completeness one have to mention Windows Scripting Host, which is available from Windows 98 and higher and is able to execute JavaScript code:

CScript.exe c:\scripts\sample.js
2
4

Check out RunJS

I recently have started using RunJS on my mac - it is such a great tool and helps me immensely to test out things quickly.

RunJS is available for the Windows machine as well. You can find download link here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .