2
0

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.

npm使い方メモ

Posted at

めっちゃ簡単にまとめます。自分用メモです。

参考

https://qiita.com/kijitoraneko/items/175ef29d45d155b3f405
https://techacademy.jp/magazine/16158

コマンド

$ npm install {パッケージ名} #ローカルインストール
$ npm install -g {パッケージ名} #グローバルインストール
$ npm install --save{パッケージ名} #依存関係をpackages.jsonに記録
$ npm install --save-dev{パッケージ名} #依存関係を開発環境用としてpackages.jsonに記録
$ npm install {パッケージ名} {パッケージ名} #複数インストール
$ npm outdated #アップデートを確認
$ npm outdated -g #アップデートを確認
$ npm update {パッケージ名} #アップデート
$ npm update -g {パッケージ名} #アップデート
$ npm uninstall {パッケージ名} #アンインストール(インストールと基本コマンドは同じ)
$ npm uninstall --save{パッケージ名} #依存関係をpackages.jsonから削除
$ npm install #packages.jsonに従ってインストール

パッケージのインストール先

グローバルインストール

環境全体から使えるモジュールをインストールします。
インストール先は $ npm list -g で調べられます。

$ npm list -g | head -n 1
/Users/ebiyuu1121/.nodebrew/node/v13.5.0/lib
# /Users/ebiyuu1121/.nodebrew/node/v13.5.0/lib/node_modules にインストールされる

ローカルインストール

カレントディレクトリの node_modules にインストールされる。(親ディレクトリのみに node_modules がある場合はそちらにインストールされるようです。

package.jsonに関して

--save オプションをつけたパッケージが記録されます。
このファイルを他の環境に移動すれば他の環境でも同じモジュールを再現することができます。
package-lock.json$ npm install $ npm update を実行した時にインストールしたバージョンを記録しています(再度 $ npm install しても同じバージョンがインストールされることを保証しています。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?