LoginSignup
84
81

More than 5 years have passed since last update.

Node.jsアプリでのパッケージ更新確認

Posted at

node.jsでは依存しているパッケージをpackage.jsonに書いておくと npm installで自動でインストールしてくれる。具体的にはこんな感じで記述。

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
     "request": "~2.27.0",
      "levelup": "~0.15.0",
      "async": "~0.2.9",
      "leveldown": "~0.8.3"
  },
  "devDependencies": {
    "coffee-script": "~1.6.2",
    "mocha": "~1.13.0",
    "chai": "~1.8.1",
    "nock": "~0.22.1"
  }
}

"モジュール名: バージョン"の並びでバージョンには"*"(任意のバージョン)も指定できるが通常はバージョン指定する。というか、モジュール導入時に

$ npm install <module_name> --save

あるいは

$ npm install <module_name> --save-dev

とすると自動でpackage.jsonの"dependencies"あるいは"devDependencies"に追加してくれる。もちろんバージョン番号付き。

で、最初の一発目は良いけど暫くたった後に「そういえば使っているモジュールのアップデート出てないかな?」と思った時に確認する方法が今日のお題。

npm outdated がそれっぽいん機能なのだが、なんだか期待していた結果が得られない。で、ちょっと探してみて見つけたのが tjunnone/npm-check-updates というモジュール。

インストールは至って簡単で、これだけ

$ npm install -g npm-check-updates

で、package.jsonのあるディレクトリで実行するだけ

$ npm-check-updates

結果としてこんなのが出てくる。

"levelup" can be updated from ~0.15.0 to ~0.17.0 (Installed: 0.15.0, Latest: 0.17.0)
"leveldown" can be updated from ~0.8.3 to ~0.9.2 (Installed: 0.8.3, Latest: 0.9.2)
"coffee-script" can be updated from ~1.6.2 to ~1.6.3 (Installed: 1.6.3, Latest: 1.6.3)
"mocha" can be updated from ~1.13.0 to ~1.14.0 (Installed: 1.13.0, Latest: 1.14.0)
"nock" can be updated from ~0.22.1 to ~0.23.0 (Installed: 0.22.1, Latest: 0.23.0)

そうそう、こういうのが欲しかった。これはアップデート可能なモジュールのリストを出してくれるだけだが、もし即にpackage.jsonに反映させたければ

$ npm-check-updates -u

これだけ。楽チンだ。

84
81
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
84
81