46
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js のrequire先pathにnpm -gでグローバルインストールしたのものを登録する

Posted at

node のrequire先path確認方法

$ node
global.module.paths

これによると、デフォルトはカレントディレクトリのnode_module。それが見つからなければ親ディレクトリのnode_moduleと見ていくらしい。

$ echo $NODE_PATH

それに加えて環境変数を見に行くらしい。

つまり
環境変数 NODE_PATHにnpm -gのlibの場所を登録すれば良い

export NODE_PATH=`npm root -g`

これはあくまで nodeのrequire先の話で、コマンドのpathを通す話とは別です

##参考

46
47
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?