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
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap