Installing node, npm and express on MacOS X

Share this post:

I’ve recently done a lot of work with Nodejs and thought I give a short installation guide on getting up and running on the Mac since there seems some confusion how to install it.

In this guide I’m using Homebrew since this is seriously the best and easiest way to install software for the Mac. Homebrew pulls downs its updates from a global repository and keeps all packages up-to-date. In the many years I’ve used Homebrew I hardly ever had any issues with it.

To install Homebrew use this (in the terminal):

[code]ruby -e "$(curl -fsSL"[/code]

Once installed, you can simply install Nodejs with:

[code]brew install node[/code]

This install node and also adds it to your path. Thus you can simply issue “node” in the terminal. Now, in order to do some serious development with Nodejs you will also want to install NPM (which stands for Node Packaged Modules) which allows you to expand Node with, e.g. Express and many other useful packages.

Luckily, installing npm is as easy as;

[code]brew install npm[/code]

With npm installed you can now install Express. Express is the web application framework written for Nodejs. Since Express is for Nodejs we can now use npm to install express into our application. But before doing so, you should understand the difference between *global* and *local* modules.

With every Nodejs application you can install modules for the application only or install them globally, so they are available to all applications. Local modules are installed in the “node_modules” within your application folder whereas global modules will be installed in a global “node_modules” folder (within the path of nodejs itself).

In order to install a module globally you simply append the “-g” flag to your install statement. In short, for installing express globally you would do:

[code]npm install express -g[/code]

If you want to install express locally to the application you first would change to the application directory and then issue a:

[code]npm install express[/code]

As mentioned, this will create a “node_modules” folder (if not already there) and place the express module in it.

There you go. In short steps you just set up a complete web development environment.

Over 10 years in business.

Self-funded. No investors. No bullshit.

More than 3,000 customers worldwide.

Helpmonks - no bullshit customer engagement service

Growth starts with action

Empower your team and delight your customers.

Helpmonks - email management for small businesses