How to Install Node.js and NPM on Mac OS

Jun 29, 2018 - 10 Comments

How to install NodeJS and NPM on Mac OS

Node JS is the popular Javascript runtime environment that is widely used by many developers, and npm is the accompany package manager for the Node.js environment and Javascript. When you install Node.js, you will find npm is installed as well, thus if you want npm you need to install NodeJS.

There are several ways to install Node.js and NPM on the Mac, including using a prebuilt packaged installer, or by using Homebrew. This tutorial will cover both, and either approach should work find on any modern version of MacOS system software.

How to Install Node.js and npm on Mac OS with Homebrew

The easiest way to install node.js and npm is with the Homebrew package manager, which means first you will need to install Homebrew on the Mac first if you have not done so already. It’s always a good idea to update Homebrew before installing a Homebrew package, so run the following command to do that:

brew update

Assuming you already have Homebrew on the Mac, then you can run the following command into the Terminal application to install both Node.js and npm:

brew install node

Installing NodeJS / NPM via Homebrew is arguably easier than using any other method, and it also makes it simple to keep node.js and npm updated. It also has the added benefit of making it relatively simple to uninstall down the road if you decide you no longer need it.

Installing Node.js & NPM on the Mac with a package installer

If you don’t want to use Homebrew for whatever reason, the other next easiest option is to use a the prebuilt installer from

You can run the installer like any other installation package on the Mac.

How to Check if NPM and Node.js are installed on a Mac

After you have installed node.js with npm, you can confirm that the two are installed by issuing either command with a -v flag to check the version:

node -v


npm -v

How to Test that Node.js is Working

Once the node.js package is installed on the Mac you can test it’s working by starting a simple web server. Create a file named “app.js” that contains the following code syntax:

const http = require(‘http’);

const hostname = ‘’;
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type’, ‘text/plain’);
res.end(‘Hello from NodeJS\n’);

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);

Save that app.js file to the current directory, then you can start the web server with the following command:

node app.js

Then launch a web browser (your default or otherwise) and go to the following URL:


You should see a message stating “Hello from Node.js”.

That simple node.js web server is sort of like the python instant web server except of course it’s using node rather than python. Speaking of Python, if you’re installing Node.js and NPM you may also be interested in instilling the updated Python 3 on a Mac too.

You can also install and use Grunt CLI task runner to test node and npm, which can be installed through npm:

npm install -g grunt-cli

You can then run ‘grunt’ from the command line.

That should just about cover the basics of installing NodeJS and npm on a Mac. If you have any other tips, tricks, suggestions, or advice, feel free to share them in the comments below.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks


» Comments RSS Feed

  1. larry says:

    It be nice it have a discussion about why to do this.

    • Peter Ragan says:

      larry, if you need nodejs and npm then you install node.js and npm. Simply, you do this if you need it. Almost exclusively for developers.

      If you don’t need node.js or npm, you would not do this. Simply, you don’t do this if you don’t need it. Which is almost exclusively everyone else.

      Like most other things in the universe, not everything is universally applicable.

  2. Luke says:

    Couldn’t you just navigate to any website which uses it, get out your javascript inspector, and copy it from there?

    • Pablo says:

      No, what you describe would be to download a javascript file from a website, whereas this is a software development library and toolkit.

      node.js is a library, npm is a package manager and sort of nearly version control for sharing code snippets. This is pretty specific for web developers really, so most people won’t have a practical need for it.

      This can be helpful if you are interested in this stuff;

      It is a good toolkit, very commonly used in programming, webdev and devops circles.

  3. Max says:

    What does NPM stand for?

  4. Steve Jackson says:

    So now I’ve installed this what can I do with it?
    (Except I haven’t installed it because I don’t know what to do with it!)

    • Peter Ragan says:

      I am always puzzled by internet comments. It’s as if people read the headline (or not even that) and then jump right to the comments to rant, rave, or opine about what they could have learned had they read the article they commented on.

      Stunningly, the very first sentence of this article answers the question posed here by Steve:

      “Node JS is the popular Javascript runtime environment that is widely used by many developers, and npm is the accompany package manager for the Node.js environment and Javascript”

      Sometimes I think there should be a quiz before allowing internet comments!

      Now giving Steve benefit of the doubt here, perhaps he is unfamiliar with javascript, package managers, and software development in general. That’s actually fairly understandable as most people have no development background. Like myself, I have no experience with certain topics but usually if something is beyond my scope I just ignore it. But let’s assume someone wants to learn, thus why they comment, learning is great! So in that case this is for developers and programmers who are already familiar with node.js as a development platform, typically those who work with web apps. If you have no prior programming experience, it can be a cumbersome task to get started, but it would be wise to start learning the general concepts first with something like an Intro to Javascript book, or something aimed at programmers for total beginners. A lot of it is just going through the motions, like learning much else, it takes a while to “stick” and it’s likely you will follow some guides to learn, have something “working” as outlined in the book, but not totally understand why, that’s just part of the learning process. Sort of like learning discrete math, or a foreign language, or a musical instrument, it’s just a matter of commitment and practice.

      As for node.js this is a helpful resource:

  5. Martin says:

    Thanks for the article, Peter. You’re responses to the comments were my favorite part though!

Leave a Reply


Shop for Apple & Mac Deals on

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad