Getting Started with JavaScript on macOS
Setting up JavaScript development on macOS is simple using Node.js and Visual Studio Code. Follow this guide to get up and running quickly.
Step 1: Install Node.js
Node.js allows you to run JavaScript outside the browser. To install it on macOS:
- Go to the official Node.js site: https://nodejs.org
- Download the macOS Installer (LTS version recommended).
- Open the downloaded `.pkg` file and follow the installation instructions.

Step 2: Verify Installation
Once installed, check that Node.js and npm are working:
- Open the Terminal app (found in Applications > Utilities).
- Run the following commands:
node --version
node --version
npm --version
npm --version
- If you see version numbers, the installation was successful.
If Node is correctly installed, you will see the version of Node displayed in the terminal, something like:
For Node.js version:
v22.x.x
v22.x.x
For npm version:
10.x.x
10.x.x
Step 3: Install Visual Studio Code
Visual Studio Code (VS Code) is a lightweight editor perfect for JavaScript development.
- Visit https://code.visualstudio.com
- Download and install the macOS version.
- Drag the VS Code app to your Applications folder, then open it.

Step 4: Write and Run Your First JavaScript Program
- Create a new file in VS Code and name it
app.js
. - Add the following code:javascript
console.log("Hello, JavaScript!");
console.log("Hello, JavaScript!");
- Save the file to a location like your Desktop.
- Open Terminal, navigate to the file's directory:
cd ~/Desktop
cd ~/Desktop
- Run the script using:
node app.js
node app.js
- Alternatively, click the ▶️ Run button in VS Code to execute it.
- You should see this output:
Hello, JavaScript!
Hello, JavaScript!
- 🎉 You're all set to start building with JavaScript on macOS!
That’s it! You’ve successfully set up a JavaScript development environment on your Mac. Happy coding!
Frequently Asked Questions
Do I need to restart my Mac after installing Node.js?
Do I need to restart my Mac after installing Node.js?
Not usually. However, if the terminal doesn’t recognize node
or npm
commands after installation, try restarting your Mac to refresh the environment variables.
What is Node.js and why do I need it on macOS?
What is Node.js and why do I need it on macOS?
Node.js is a JavaScript runtime that allows you to run JavaScript code outside the browser. It's essential for developing JavaScript applications on your Mac.
How do I check if Node.js is installed on macOS?
How do I check if Node.js is installed on macOS?
Open the Terminal and type node --version
and npm --version
. If you see version numbers, Node.js and npm are installed correctly.
Can I use another code editor instead of VS Code on macOS?
Can I use another code editor instead of VS Code on macOS?
Yes, you can use any code editor you prefer, such as Sublime Text or Atom. However, VS Code is highly recommended due to its features, extensions, and macOS integration.
How do I run JavaScript files from the terminal on macOS?
How do I run JavaScript files from the terminal on macOS?
Navigate to the folder where your JavaScript file is saved using the cd
command and run it with node filename.js
.
What if node
is not recognized as a command on macOS?
What if node
is not recognized as a command on macOS?
This typically means that Node.js wasn't added to your PATH. Reinstall Node.js and ensure the 'Add to PATH' option is checked during setup.