Installing SKPM (Sketch Plugin Manager) via npm - node.js

I've been attempting to install a npm package, which has been throwing a bunch of errors which I'm not too familiar with. Keep in mind that these errors are after executing sudo npm install -g skpm:
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/skpm/node_modules/keytar/build'
gyp ERR! System Darwin 17.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/skpm/node_modules/keytar
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keytar#4.1.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keytar#4.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USERNAME/.npm/_logs/2017-12-19T01_53_44_910Z-debug.log
Originally I'd thought that I needed to install keytar to make this work, but after installing I still had the same errors.

Avoid use sudo npm -g install
During gyp compilation you will have such problems again and again.
Fixing permissions is the solution.
Quote from npm docs:
You can fix this problem using one of three options:
Change the permission to npm's default directory.
Change npm's default directory to another directory.
Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.
Option 1: Change the permission to npm's default directory
Find the path to npm's directory: npm config get prefix For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2 or you
will mess up your permissions.
Change the owner of npm's directories to the name of the current user
(your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home
folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Option 3: Use a package manager that takes care of this for you.
If you're doing a fresh install of Node on Mac OS, you can avoid this
problem altogether by using the Homebrew package manager. Homebrew
sets things up out of the box with the correct permissions.
brew install node

usually EACCES: permission denied occurs trying to install a package globally (with -g) without providing permissions. Supposing that you are on os with sudo, try call
sudo npm install -g skpm
or, if you don't want it global
npm install skpm

I found the issue as to why skpm was not installing.
Make sure you install x-code + command line tools access
This fixed the issue and SKPM installed.

Related

How can I install `bcrypt-as-promised` from an old code base onto my ubuntu box?

I'm working with an old code base from an old project that uses bcrypt-as-promised (before bcrypt allowed the use of promises). When I try and npm install the package.json, I receive this error for that package:
npm WARN deprecated bcrypt-as-promised#1.1.0: the bcrypt module supports promises now, this module is no longer necessary
npm WARN deprecated bcrypt#0.8.7: bcrypt < v2.0.0 is susceptible to bcrypt wrap-around bug. Upgrade to bcrypt >= v2.0.0 for improved support for newer bcrypt hashes
And then proceeds to fail (I can paste more of the error message if needed).
I'm a little confused as to how I might be able to get this now deprecated package to install. I thought about modifying the codebase to only use bcrypt (with the now native promises supported), but I'm afraid of diving into a bee's nest and breaking the application. I was wondering first if there might be a way to install this package for the old code base to get it working.
Any thoughts? Thanks for your time and any insight you may have.
My package.json: https://github.com/twknab/mean_hike/blob/master/package.json
// Edit:
Here's the full terminal message I receive when I try and sudo npm install:
> bcrypt#0.8.7 install /var/www/mean_hike/node_modules/bcrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir
'/var/www/mean_hike/node_modules/bcrypt/build'
gyp ERR! System Linux 4.4.0-1072-aws
gyp ERR! command "/usr/local/bin/node"
"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/mean_hike/node_modules/bcrypt
gyp ERR! node -v v11.2.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt#0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt#0.8.7 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2018-11-27T10_46_27_925Z-debug.log
Older versions of bcrypt can be quite tricky to install, and it looks like you're hitting a classic permissions issue with npm. You can try some of the tips listed in the official documentation here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
… but in the meantime, here are a few things to try:
Attempt a global install of node-gyp first, either with or without
sudo: npm install node-gyp -g
If that works, then try installing
bcrypt (again, globally).
If you're still seeing permissions issues,
you may need to sort out ownership of your node_modules directory:
sudo chown -r XXX /usr/lib/node_modules/ (assuming that's where
the global modules directory is on your machine of course).
I found a solution to my issue was to use yarn to import all of my dependencies rather than npm, while also swapping bcrypt-as-promised for bcrypt (which now includes promises with no syntax changes necessary).
I ditched bcrypt-as-promised and replaced it with bcrypt in my package.json file.
I then changed any instance of require('bcrypt-as-promised') to require('bcrypt') (the syntax for using bcrypt remains the same, just the dependency importation lines need to change).
Without using yarn, even after changing my folder permissions, I was still hitting permissions "EACCES: permission denied" errors, with only bcrypt failing. My versions of npm and node seemed fine. Made sure my Ubuntu box was all updated.
That's when I gained the suggestion from a wise friend to try using yarn to grab the dependencies instead. I ran yarn import which reads the package.json file and creates a yarn.lock file. I then installed yarn on my ubuntu machine (sudo npm install yarn -g), and ran yarn install, and bcrypt successfully installed!
Update Jan 2019 - Improved Solution
It looks like if npm dependencies were originally installed using sudo, permission issues can be experienced when trying to install bcrypt. My improved solution was to:
Nuke the ./node_modules folder via sudo rm -r ./node_modules
Install npm packages fresh (not using sudo).
After this, I was able to npm i --save bcrypt with the package installing
successfully.
Here's a link from GitHub that helped me find the solution and an excerpt:
#Mayocampo permission denied, mkdir
'/home/someroute/node_modules/bcrypt/build'
It seems you run rpm as root, therrfore your account cannot mkdir
under /home/someroute/node_modules/ Check dir with ls -l
/home/someroute/node_modules/ Im sure owner of upper dir is root. or
your account cannot have permission.
I guess there are two options are available.
sudo rm -r ./node_modules And install package via npm
again, but without using sudo.
Change mod ./node_module to access and excutable. I decided first, and its fixed
Source: juicycool92 # GitHub

Error: EACCES, permission denied even after using sudo?

I am trying to set up a chrome extension that will automatically save the changes I make to my website with the inspect element feature. The idea is that you'll be able to make real time changes to the website without having to go back into the ide to save the changes and re-upload and everything. The extension is called DevTools Autosave. I've been following the instructions from this site. I'm trying to install this on a mac.
I've installed node.js and the extension already. When I got to the part in the instructions where it talks about which commands to run in the terminal I've tried both with and without the "sudo" in front of the "npm install -g autosave" command but I always get this error:
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
npm ERR! autosave#1.0.3 install: `node ./scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the autosave#1.0.3 install script.
npm ERR! This is most likely a problem with the autosave package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls autosave
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "autosave"
npm ERR! cwd /Users/Brent
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
Anyone know how I can fix this? I can't find anyone that is having this problem and I've been on a few different forums now but can't find a solution. Thanks in advance.
You have two options: Either fix your npm setup, so you can use npm -g, or install autosave locally.
To install locally (i.e. in node_modules within your current directory), run npm install autosave (without -g). Then you can run ./node_modules/.bin/autosave or ./node_modules/autosave/bin/autosave to start autosave.
To fix your npm setup, so you can use -g without root permissions (recommended):
In your home dir (assuming /Users/Brent/), create a file called .npmrc with the following content:
cache = /Users/Brent/.npm/cache
globalconfig = /Users/Brent/.npm/npmrc
globalignorefile = /Users/Brent/.npm/npmignore
prefix = /Users/Brent/.npm
And add ~/.npm/lib/node_modules to your NODE_PATH, e.g. by putting the following in .bashrc (assuming that your shell is bash) to allow the modules to be found, and append ~/.npm/bintoPATHso you can run any installed binary (i.e. runautosave` from anywhere):
export NODE_PATH=$HOME/.npm/lib/node_modules
export PATH=$PATH:$HOME/.npm/bin
(changes to .bashrc only take effect when you load the shell, or use . ~/.bashrc; if you want to use the new setup without reloading the shell, just run that line (export ...) in your current shell).
As of 2020, here is the recommended solution by npm. It worked for me (OSX). (No need to change any path configuration or .bashrc)
Steps:
Install nvm by running below command.
If you are using bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
If you are using zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | zsh
Install node using nvm (No need to uninstall existing node/npm)
nvm install 12.13.1

NPM won't install any package on Mac. New, clean build. `EACCES` & other errors

I've just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.
I installed Git via their git-2.0.1-intel-universal-snow-leopard.pkg (http://git-scm.com/downloads) in their default /usr/local/git/bin/git location.
I installed Node via their node-v0.10.30.pkg (http://nodejs.org/download/) in their default /usr/local/bin/node location.
The final step of Node's installer package included a note that they also installed NPM in their default /usr/local/bin/npm location.
My $PATH echoes /usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin (it contains /usr/local/bin).
Running npm install -g bower results in:
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Home
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Home/npm-debug.log
npm ERR! not ok code 0
Running similar installations (npm install -g yo, npm install -g grunt, npm install -g nvm, npm install -g npm) results in what appears to be the same list of errors.
Several people online suggest forcing the installation via sudo, but several others warn this could cause later issues. The manuals for these packages seem not to mention requirement of sudo, and in some cases, they have advised contacting NPM when this issue arises.
Running npm cache clear does not correct the issue.
Running ls -la in the home (~) directory shows my Mac OS X username as the owner of my .npm directory: drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm
Does anyone know what has gone wrong and how to correct this? Thank you.
By the way, I solved this issue by changing the owner of /usr/local to be myself, in order to allow NPM to modules in its default location without further requiring sudo for each package's installation.
sudo chown -R `whoami` /usr/local
EACCES is an error of not having access on doing an operation.
Taken the line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' we can see that npm was unable to create a directory in the given location.
The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:
npm ERR! Please try running this command again as root/Administrator.
To run as administrator, you have to prefix those commands with sudo. That is:
sudo npm install -g bower. You will be required to type in a password for security reasons.
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
to install nodejs and npm as yourself NOT root do these commands (linux) :
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
cd v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax : npm install xxxxx -g
always use the -g for global
nodejs install gives you npm as well :
ls -la ${HOME}/bin/nodejs/bin
I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:
First, you can manage multiple versions of Node.js on the same machine (which you will want to do sooner or later).
Second, you get around all the access problems you experience when installing Node.js without it. At least that's my experience.
Basically it's as easy as running
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
from the command line.
(SOLUTION ANSWER)
Hi Guys,
I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)
You could simply add "sudo" before your commands what will force it.
For example:
sudo npm install gulp -g
or
sudo npm install browser-sync -g
Enjoy!
It's generally not advised to run sudo unless absolutely necessary.
For issues like this, NPM can solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.
I had a similar issue setting up a new machine, and installing NPM took care of the issue.

nodejs npm package | npm link issue

I am trying to make a npm package (plugin) to install the little JS framework through node, have come up with the required package.json as well.
After running the npm link command on Mac terminal, got to see the following errors.
npm ERR! Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR! { [Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Repos/GIT/JavaScript-Boilerplate' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "link"
npm ERR! cwd /Repos/GIT/JavaScript-Boilerplate
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Repos/GIT/JavaScript-Boilerplate
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Repos/GIT/JavaScript-Boilerplate/npm-debug.log
npm ERR! not ok code 0
P.S. I am pretty new to nodejs but have strong experience in JavaScript, let me know if you need more detail around.
EDIT - Got to resolved the issues given above but now getting more issues as below:
6495 verbose false,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/node_modules unbuild contextify#0.1.5
6496 info postuninstall contextify#0.1.5
6497 verbose about to build /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery
6498 info /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery unbuild
6499 verbose from cache /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/package.json
6500 info preuninstall jquery#1.8.3
6501 info uninstall jquery#1.8.3
6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild jquery#1.8.3
6503 info postuninstall jquery#1.8.3
6504 error contextify#0.1.5 install: `node-gyp rebuild`
6504 error `sh "-c" "node-gyp rebuild"` failed with 1
6505 error Failed at the contextify#0.1.5 install script.
6505 error This is most likely a problem with the contextify package,
6505 error not with npm itself.
6505 error Tell the author that this fails on your system:
6505 error node-gyp rebuild
6505 error You can get their info via:
6505 error npm owner ls contextify
6505 error There is likely additional logging output above.
6506 error System Darwin 12.3.0
6507 error command "node" "/usr/local/bin/npm" "link"
6508 error cwd /Repos/GIT/JavaScript-Boilerplate
6509 error node -v v0.10.4
6510 error npm -v 1.2.18
6511 error code ELIFECYCLE
6512 verbose exit [ 1, true ]
enter code here
enter code here
Looks like I am close to it :)
Permissions you used when installing Node will be required when doing things like writing in your npm directory (npm link, npm install -g, etc.).
You probably ran node installation with root permissions, that's why the global package installation is asking you to be root.
Solution 1: NVM
Don't hack with permissions, install node the right way.
On a development machine, you should not install and run node with root permissions, otherwise things like npm link, npm install -g will need the same permissions.
NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.
Uninstall Node (root permission will probably be required).
To remove all previously installed npm global modules, see those answers.
Then install NVM following instructions on this page.
Install Node via NVM: nvm install stable
Now npm link, npm install -g will no longer require you to be root.
Solution 2: Install packages globally for a given user
Don't hack with permissions, install npm packages globally the right way.
If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup npm and node to know how to find globally installed packages.
Check out this great article for step by step instructions on installing npm modules globally without sudo.
See also: npm's documentation on Fixing npm permissions.
The easiest way to solve this would be to run the same command again using sudo:
sudo npm link
Please don't change the owner of the /usr/local directory, as this might a) have further implications on installed application and b) might compromise the security on your system. Using sudo is the right way to solve this.
This can be fixed in linux or in my case WSL by setting the global package directory to be in user space rather than root.
First create a dir for global packages
mkdir ~/.npm-packages
Then tell npm where to store globally installed packages
npm config set prefix ~/.npm-packages
Finally ensure npm will find installed binaries and man pages by adding the following to your .bashrc/.zshrc:
NPM_PACKAGES=~/.npm-packages
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

Getting errors when trying to install socket.io globally

I am new to node, npm, socket.io. Found many guides that are fairly useful, but I am encountering some errors which I don't understand the cause, hopefully you can help me out.
npm install socket.io -g
returns ...
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm ERR! error installing socket.io#0.9.4
npm ERR! error rolling back socket.io#0.9.4 Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "socket.io" "-g"
npm ERR! cwd /Users/Kinglee
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.0-beta-4
npm ERR! path /usr/local/lib/node_modules/socket.io/.npmignore
npm ERR! code EACCES
npm ERR! message EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Kinglee/npm-debug.log
however when i did npm install socket.io, there was no error, everything was fine.
Sorry forget to add this info here ...
I actually tried sudo npm install socket.io and it installed without error but when i try to cd ~/node_modules, I don't see socket.io, this cause 'socket.io not found' error when i try to do require('socket.io') as I follow this tutorial here (http://blog.koostudios.com/?p=470)
Kind of confused fellow here :/
The most important portion is:
EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
This means you do not have permission to delete this file.
I assume this means you ran the command as your standard user account, which will not have write permission into /usr/.
Prepend sudo to your command to re-run the command with administrator privileges:
sudo npm install socket.io -g
Your local configuration may not have /usr/local/lib/node_modules/ in node's default module loading locations. The module loading path is controlled via the NODE_PATH environment variable (before starting node) or the require.paths variable (once node is running). Because I prefer to keep local configuration separated from the program, I'd prefer to set the environment variable to modify paths, though the other mechanism may be useful for long-lived applications that must remain up even when the environment changes. (This is definitely an advanced use.)
To change the NODE_PATH variable for a single instance, sh and its derivatives will let you simply add NODE_PATH=/path before the command. For example, change:
node ./foo.js
to
NODE_PATH=/usr/local/lib/node_modules ./foo.js
If you have multiple directories, use the standard :-separated directories, just as you would for PATH:
NODE_PATH=/usr/local/lib/node_modules:/home/sarnold/node_modules ./foo.js
To make this persistent, use the shell's export builtin to export the value of the NODE_PATH variable to all children and place the modification in your shell's start up files, such as ~/.bashrc:
export NODE_PATH=/usr/local/lib/node_modules
This will take effect in all new shells automatically. You can source this file into currently-running shells if you don't wish to restart them:
source ~/.bashrc
Just leaving this here, as it helped me with a similar problem:
NPM no longer working
Had some good answers.
Hope it helps.

Resources