How to Run a Node.js Application on a Mac

Node.js makes it possible for you to run JavaScript programs outside of a web browser or on a server. To run a Node.js application on MacOS, follow these three steps.

Open Terminal by pressing Command+Space to open Spotlight Search and entering terminal into the search box.

Enter the following command, then press Return to create a file named test-node.js containing a simple application that will print out the result 1 + 1.

echo "console.log(1+1);" >> test-node.js

Type node followed by the name of the application, which is test-node.js in this case, and then press Return.

node test-node.js

The result of running the application will be printed out to the terminal.

Author: Chris Minnick

Chris is a prolific author and trainer, and the CEO of WatzThis?. His published books include Writing Computer Code, JavaScript for Kids, Coding with JavaScript For Dummies, Beginning HTML5 and CSS3 For Dummies, Webkit For Dummies, CIW eCommerce Certification Bible, and New Riders' XHTML.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.