How to Run JavaScript on Mac Terminal

We can run JavaScript on Mac terminal just the nodeJS package.

The quickest way to get nodeJs on Mac is by making use of the brew package manager.

brew install node

Make sure you have brew installed on your Mac, if not - How to install home-brew on Mac

Once the installation is complete, just type node to enter the Node REPL (Read-Eval-Print Loop) environment, here you can run your JavaScript code snippets.

% node

> console.log("Hello JavaScript!")

Hello JavaScript!
Run JavaScript in Mac Terminal

How to run JavaScript file using Mac Terminal

Again we can make use of node package to run .js files in Terminal.

script.js

console.log("Hello!")
% node script.js

Hello!
Run JavaScript js file from Mac Terminal

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!