Install and Test Node.js on Mac OS

Download Node.js for Macintosh

Step 1: First download and install Node.js Macintosh installer from official website. You need to install Xcode on your mac.

Step 2 : Open terminal and type mate node.js. Its open Text mate

Type console.log(‘Application Working’); and save the file.

Step 3: Next type node test.js in terminal. press enter button.

Its show ‘Application Working”.

If you want to run any JavaScript in Node.js, you need to create JavaScript file like this,

var os = require("os");
var msg = 'Your System running under '+ os.platform() +' OS.';

The first one is the require function.

var os = require("os");

When you use a require statement, node searches for what’s called a module. In this case we specify to load os module. Require function return the object which represents all of code available in os module.

Save this example script as os.js file.

Now open your Command Prompt and change the directory to desktop.

Type node os.js

This script pull information from operating system and display in command line.

Try different operating system based utility functions in nodejs.

Try to run JavaScript files using this kind of method to learn Node.js.