8

Is there any way to write and run a JavaScript code without having a need to run a browser and use its JavaScript engine?

Thanks!

pencilCake
  • 45,443
  • 73
  • 211
  • 346

7 Answers7

5

I am amazed no one has pointed this out yet.

Windows includes a Javascript engine that can be used from the command line.

All versions of Windows, since Windows 98, have included something called "The Windows Script Host". It's a windows-standard way to support script "engines". Since the first release, WSH supports JScript, Microsoft's version of Javascript. Among other things, this means that, from a windows command line, you can just invoke the name of any *.js file, and it will run in the JScript engine. (via either wscript.exe or cscript.exe)

You can see this question: What is the ProgId or CLSID for IE9's Javascript engine (code-named "Chakra") to learn how to invoke the higher-performance IE9 Javascript engine from cscript.exe.

I use cscript.exe to run jslint from within emacs, on any .js module I'm editing. (via flymake-for-js) Lots of people use .js modules to do system maintenance or administration.

Community
  • 1
  • 1
Cheeso
  • 180,104
  • 92
  • 446
  • 681
1

Take a look at Rhino JS Engine.

Anupam Jain
  • 7,323
  • 2
  • 34
  • 71
1

There's node.js

http://nodejs.org/

bbg
  • 2,556
  • 2
  • 17
  • 13
1

On top of that, you can take a look at jslib http://code.google.com/p/jslibs/ which uses spidermonkey, the core of javascript engine in firefox.

drhanlau
  • 2,437
  • 2
  • 21
  • 38
1

Java 6 has support for executing JavaScript within Java code. You can load any arbitrary JS file and execute (eval) it.

Here's a simple code example for the same: http://www.java2s.com/Code/Java/JDK-6/ExecuteJavascriptscriptinafile.htm

Param
  • 2,112
  • 1
  • 12
  • 10
0

Might as well throw Google's V8 engine into the ring

Please see JasonMP85's answer for a few more options as well.

Community
  • 1
  • 1
Khepri
  • 9,297
  • 5
  • 41
  • 60
0

There are tons of independent, js engines, adding to previous post

There are tons of standalone JS engines and framework built on top of them (Node.js, ringojs, etc.)

http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions

Well, all you need is to choose based on what you need.

OnesimusUnbound
  • 2,832
  • 3
  • 29
  • 38