I may have messed something up with my installation, I don't know.
I reinstalled node with N package manager (script? package?) some time ago to solve sudo
problems for my global packages, and today I encountered a problem -- I couldn't require globally installed packages in the node REPL (require('lodash')
for example).
I am pretty sure I have something messed up with my node setup, but the more I skim through the web the more confused I am -- what are $NODE_MODULES
, $PREFIX
, .../lib/node
, .../lib/node_modules
, $N_PREFIX
, which and why are obsolete, what are the differences etc.
My current setup looks like that:
# fragment of ~/.bashrc
# setup NODE
export N_PREFIX="$HOME/.n"
export PATH=$N_PREFIX/bin:$PATH
directory structure:
# output of `tree $N_PREFIX -L 2`. Arrows are symlinks, bin/node is executable
/home/tooster/.n
├── bin
│ ├── check -> ../lib/node_modules/checker/cli.js
│ ├── eslint -> ../lib/node_modules/eslint-cli/bin/eslint.js
│ ├── eslint-cli -> ../lib/node_modules/eslint-cli/bin/eslint.js
│ ├── ffmpeg-bar -> ../lib/node_modules/ffmpeg-progressbar-cli/lib/main.js
│ ├── js-yaml -> ../lib/node_modules/js-yaml/bin/js-yaml.js
│ ├── node
│ ├── npm -> ../lib/node_modules/npm/bin/npm-cli.js
│ ├── npx -> ../lib/node_modules/npm/bin/npx-cli.js
│ ├── tsc -> ../lib/node_modules/typescript/bin/tsc
│ └── tsserver -> ../lib/node_modules/typescript/bin/tsserver
├── include
│ └── node
├── lib
│ └── node_modules
├── n
│ └── versions
└── share
├── doc
├── man
└── systemtap
And the return of 'module' from Node REPL:
Module {
id: '<repl>',
path: '.',
exports: {},
filename: null,
loaded: false,
children: [],
paths: [ <-- None of these actually exist
'/home/tooster/repl/node_modules',
'/home/tooster/node_modules',
'/home/node_modules',
'/node_modules',
'/home/tooster/.node_modules',
'/home/tooster/.node_libraries,
'/home/tooster/.n/lib/node'
]
}
I cannot find any info about difference between the .../lib/node
and .../lib/node_modules
. Symlinking latter to the former seems to work, but I don't know what are consequences of doing that, so I'd rather not do that blindly.
Also npm config get prefix
returns /home/tooster/.n
.
How should a proper installation of npm with N look like? I want to have my globally installed packages available in REPL, because I often write quick scripts in Node.