Node.js + NPM + Express すべて最新バージョンに update する方法

Node.js と npm と Express も、すべて最新バージョンに update する方法をご紹介します。

Express | Node.js

前提条件

本記事は以下の GitHub Pull Request を元に説明しています。全体的な変更内容は Pull Request を直接ご確認ください。

Update Node.js version to v10.16.3 & npm update · Pull Request #2 · codenote-net/expressjs-sandbox

Node.js, Express version

  • Node.js version 8.11.1 -> 10.16.3
  • Express version 4.16.0 -> 4.17.1

npm version

npm version は以下の commit を参照してください。Express プロジェクト作成初期に npm install したものがほとんどなので、特殊な npm は無いと思います。

npm update [2019-10-07] · Pull Request #2 · codenote-net/expressjs-sandbox

Update Node.js & NPM version 手順

Node.js LTS 最新バージョン install

$ nvm install --lts
Installing latest LTS version.
v10.16.3 is already installed.
Now using node v10.16.3 (npm v6.9.0)

併せて .node-version ファイルがあればその version も変更します。

diff --git a/.node-version b/.node-version
index d3a8b24..70047db 100644
--- a/.node-version
+++ b/.node-version
@@ -1 +1 @@
-v8.11.1
+v10.16.3

Update Node.js version to v10.16.3 & npm update · Pull Request #2 · codenote-net/expressjs-sandbox

Install npm-check-updates

$ npm install -g npm-check-updates

npm-check-updates –upgrade で npm update

npm-check-updates --upgrade
npm install

で package.json にたくさん diff ができますが、問答無用で npm install して、自動テストを実行させたり、動作確認しましょう。

Update Node.js version to v10.16.3 & npm update · Pull Request #2 · codenote-net/expressjs-sandbox

以上、Node.js version と npm update してすべて最新バージョンに上げた、現場からお送りしました。