Basic Node

Node on Mac

Basic Node

by John Vincent


Posted on February 18, 2017


This stuff ends up sprayed everywhere, so let's create a reference document.

Node

NodeJS

Install / Update

From NodeJS

installs to

/usr/local/bin/node
/usr/local/bin/npm
which node
which npm

Check versions

node -v
npm -v

Global Node modules are kept in /usr/local/lib/node_modules

Path

Ensure /usr/local/bin is in your PATH

Update Npm

One option is to update by updating Npm as outlined above.

Preferred

sudo npm install -g npm 

Npm Global Modules

For example

sudo npm install -g less

will install less as /usr/local/bin/lessc

Update Global Modules

For example

sudo npm update -g less

Npm Cache

cd
cd .npm
ls

will show the cached files.

Npm Clean Cache

sudo npm cache clean

Npm Error

For example

npm list -g grunt
Unmet Peer Dependency grunt@~0.4.2

may require some upgrades.

Package Install

For example

npm install underscore
npm install underscore@1.7.0

sudo npm update underscore

npm uninstall underscore

Search for a Package

sudo npm search mkdir

shows packages including mkdir allowing for sudo npm install -g mkdirp

Nodemon

Nodemon

sudo npm install -g nodemon

nodemon server.js

Use a Package

For example mkdir.js

var mkdirp = require('mkdirp');
mkdirp('foo', function (err) {
    if (err) console.error(err)
    else console.log('Directory created!')
});

and then

node mkdir.js

creates directory foo

DevTool - NodeJS Debugger

sudo npm install -g devtool

devtool app.js —break

Less

Less

sudo npm install -g less

lessc styles.less styles.css
lessc styles.less ../css/styles.css

Yarn

Yarn

npm install -g yarn

yarn -v

uglifyjs

sudo npm install uglify-js --global

uglifyjs mkdir.js -o mkdir.min.js

Grunt

Grunt

sudo npm install -g grunt-cli
sudo npm install -g grunt-init
grunt --version

grunt-cli v0.1.13

Other

npm config list
npm config get prefix

npm list --global
npm list -g --depth=0
Basic HomebrewInstall Sass on Mac