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
You can also use phantomjs
Download phantomjs depending on the system (my case is Max OSX) from phantomjs.org
.You should put the path to phantomjs installation folder on the top of your javascript file. eg. #!./bin/phantomjs
Save your code. Go to the terminal where your javascript is saved and you can run using > phantomjs filename.js
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.
I tried researching that too but instead ended up using jsconsole.com by Remy Sharp (he also created jsbin.com). I'm running on Ubuntu 12.10 so I had to create a special icon but if you're on Windows and use Chrome simply go to Tools>Create Application Shortcuts (note this doesn't work very well, or at all in my case, on Ubuntu). This site works very like the Mac jsc
console: actually it has some cool features too (like loading libraries/code from a URL) that I guess jsc
does not.
Hope this helps.
This is a "roundabout" solution but you could use ipython
Start ipython notebook from terminal:
$ ipython notebook
It will open in a browser where you can run the javascript
All the answers above are great, I see one thing missing and could be considered for running javascripts(*.js)
files, the unrelated brother of javascript
the Java
.
JDK
comes up with two nice tools, could be utilized for executing javascripts
.
Here are command goes like. Make sure to navigate to JDK\bin
.
jjs example.js
Its comes up with another commmand
tool that goes like this-
jrunscript example.js
I hope this may be helpful to others.
On Ubuntu, install libjavascriptcoregtk-3.0-bin and use /usr/bin/jsc
(manpage).