Reputation: 104
I'm trying to install packages into a project, by using npm install packagename
. The install then goes on to install into /home/myusername/node_modules/packagename/node_modules/
. Why is this happening? I'm guessing this has to do with the $NODE_PATH set in .bashrc.
Being new to Linux, I've copy pasted a lot. So, my .bashrc looks a bit messed up. This is all that's related to Node / NPM in my bashrc. Please help me so that the installations are the way they're supposed to.
# Allows for installing npm packages globally without sudo
NPM_PACKAGES="~/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
export NODE_PATH=~/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export NODE_PATH=/home/anton/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules:/home/anton/npm/lib/node_modules
export NODE_PATH=/home/anton/.npm-packages/lib/node_modules:/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/anton/.npm-packages/lib/node_modules:/home/anton/npm/lib/node_modules
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
Thanks in advance, Anton
Upvotes: 0
Views: 858
Reputation: 75
I had a similar problem: the packages were installed not in the project folder I was in, but in the /Users/me directory.
My fix: initialize npm and create a package.json file in the project folder, by running npm init.
The post "npm install module in current directory" helped me get to this solution.
Upvotes: 1
Reputation: 745
I believe I understand your question. You are trying to have an install go into a certain directory.
If this is true, then you want to look into the command chroot
or change root.
This will change the root directory to the current directory.
For example:
cd /your/project/directory
chroot ./chroot
Which will then change your root directory to the project's directory and install all files there. For more information look here: http://man7.org/linux/man-pages/man2/chroot.2.html
Upvotes: 0