Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a Javascript runtime interpreter installed on OS X?

With OS X Xcode installed one can run ruby code in terminal with ">ruby somefile.rb" command (or from inside TextWrangler with the run command). You can also run a ruby interpreter from in terminal and type code in single lines while the interpreter retains variable objects.

Want same possibilities for Javascript. What must I install (if anything) on OS X to have that functionality? Not looking for an IDE as such just an interpreter that will run in Terminal.app?

I assume this is an allowed question for Stackoverflow based on other allowed questions about IDEs for various languages like: What's a good IDE for Python on Mac OS X?

like image 883
wide_eyed_pupil Avatar asked Apr 09 '12 10:04

wide_eyed_pupil


People also ask

How do I run a .JS file on a Mac?

In the Shortcuts app on your Mac, double-click a shortcut. In the shortcut editor, click at the top of the action list, begin typing “Run JavaScript…” in the search field, then double-click the Run JavaScript on Active Safari Tab action to add it to the shortcut editor.

What is JavaScript runtime built?

It's built on Chrome's V8 JS engine which is written on C++. Node. js run a JS program directly and compiles it to machine code. Then OS execute this machine code.

How do I run node on OSX?

To write and run a NodeJS program on mac, first download and install the LTS version of NodeJS from its official website. After installation, create a new JavaScript(. js) file, write some code inside it, and run the “node fileName. js” command in the terminal.


3 Answers

There is a Javascript interpreter in the JavaScriptCore framework that comes with OS X. The interpreter is called jsc and can be found at the following path:

 /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Helpers/jsc

There is a built-in function, quit(), which will exit interactive mode.

If you want to make it easier to use I suggest creating a symlink to a location in your path, e.g.:

sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Helpers/jsc /usr/local/bin

This will put a symbolic link in /usr/local/bin.

like image 93
mttrb Avatar answered Sep 18 '22 13:09

mttrb


Node.js. It's the V8 engine + libraries + REPL.

Although Node is usually used for web/network-related applications, at its core it's just a plain JS engine and can even be used for shell scripting.

You can install it from the installer, brew or just ./configure && make from a Node.js' tarball.

There's also Rhino.

like image 30
Kornel Avatar answered Sep 20 '22 13:09

Kornel


v8. Its the javascript engine used in google chrome. You have to compile it for mac OS X, though. Theres a good tutorial here.

like image 22
pbfy0 Avatar answered Sep 18 '22 13:09

pbfy0