Skip to content

Instantly share code, notes, and snippets.

@rosswd
Last active May 11, 2023 13:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rosswd/acceded358c664b13174 to your computer and use it in GitHub Desktop.
Save rosswd/acceded358c664b13174 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

1. Use the jsc alias as a REPL

jsc

2. Run a script using the jsc alias

Create a file and save it. Change to the saved directory and execute the file:

jsc hello.js

Using Node.js

Install Node using homebrew

brew update && brew install node

1. Bring up the REPL:

node

2. Run a script:

Create a file and save it. Change to the saved directory and execute the file:

node hello.js

Using PhantomJS

Install phantomjs using homebrew

brew update && brew install phantomjs

1. Bring up the REPL:

phantomjs

2. Run a script:

Create a file and save it. Change to the saved directory and execute the file:

phantomjs hello.js

@hmrasi
Copy link

hmrasi commented Jan 19, 2018

I'm trying to run a single line of JavaScript in the command prompt. How can it be possible? or again i have to read the command output in the javascript!

@Rahizo
Copy link

Rahizo commented Nov 18, 2018

I am not sure whether these all go on the same terminal line

@rosswd
Copy link
Author

rosswd commented Jan 10, 2019

@Rahizo yes these are all terminal commands and are entered one at a time as shown

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