Skip to content

Instantly share code, notes, and snippets.

@alejandrosuarez
Forked from rosswd/js-cmd-line.md
Created May 11, 2023 13:54
Show Gist options
  • Select an option

  • Save alejandrosuarez/cd1883bca567a8825e7553c1138708b5 to your computer and use it in GitHub Desktop.

Select an option

Save alejandrosuarez/cd1883bca567a8825e7553c1138708b5 to your computer and use it in GitHub Desktop.
Running Javascript from the command line.

Running JavaScript from the command line

I get quite frustrated running JS by pasting into Chrome/FF and sometimes I like to keep everything local. These are some notes on using Apple's built in intrerpreter, node or phantom.

Using Apple's built in interpreter

Create a symlink by putting jsc into /usr/bin

sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /usr/bin

Bring up the REPL

jsc

Run a script

jsc hello.js

Using Node.js

Install Node using homebrew

brew update && brew install node

Bring up the REPL:

node

Run a script:

node hello.js

Using PhantomJS

Install phantomjs using homebrew

brew update && brew install phantomjs

Bring up the REPL:

phantomjs

Run a script:

phantomjs hello.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment