For instance, if you were to run a Python script you would type python filename.py or if you wanted to run a C program make filename then ./ filename. How do you do this with .js files?
If you have Rhino (or alternative) installed and on your path, then running JS can indeed be as simple as
> rhino filename.js
location.href, and create output by appending DOM objects rather than calling
If you’ve got hold of a script which was written for a web page, you may need to wrap or modify it somewhat to allow it to accept arguments from stdin and write to stdout. (I believe Rhino has a mode to emulate standard browser global vars which helps a lot, though I can’t find the docs for this now.)
Another answer would be the NodeJS!
Using terminal you will be able to start it using
$ node > 2 + 4 6 >
Note: If you want to exit just type
If you have a Mac you can get
You could also run one of your .js script by adding its name as an argument for jsc, like this:
Notice: I use
console.log() during development but jsc needs the
debug() function instead.
On Windows as other people said you can rely on
wscript directly built on the OS.
Use node.js for that, here is example how to install
node by using
brew on mac:
brew update && install node
Then run your program by typing
node filename.js, and you can use
console.log() for output.
If your using windows.
- Set up
node.jsin your system and open up
- Open the
node.jscommand prompt, navigate to your directory, where you have saved your js file.
- and execute your js file by giving a command