You can build it from source or look for it in your system’s package manager.
Before I continue, SpiderMonkey defines a few functions which are useful for non-browser environments. In the following examples, I’ll be using the print function which outputs a string to STDOUT.
Execute (-e) mode:
File (-f) mode:
File (-f) mode (multiple files):
Apart from “print”, there are other useful functions:
Command Usage Description ======= ===== =========== load load(['foo.js' ...]) Load files named by string arguments readline readline() Read a single line from stdin print print([exp ...]) Evaluate and print expressions help help([name ...]) Display usage and help messages quit quit() Quit the shell clear clear([obj]) Clear properties of object
This is an abridged version of the available functions, here’s the full one.
The ability to import other files (load), read from STDIN (readline), output messages (print), and quit are exactly what’s needed for scripting. In fact, while I was googling for SpiderMonkey, I found this post which used SpiderMonkey as a primitive CGI script.