nodemon

nodemon の公式サイトは Github で OK???

nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

まじかよ!神ツール

nodemon は開発時のみ使用するので -D オプションをつけてインストール。

$ npm i -D nodemon@2.0.6

package.jsonスクリプトを追記

  "scripts": {
    "start": "node app",
    "watch": "nodemon app"
  },

早速起動する。

$ npm run watch

> todo-express@1.0.0 watch /home/yasuji/WorkSpace/todo-express
> nodemon app

[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`

ホットリロードが有効になった。ソースコードの修正・訂正の度に再起度の必要がない。これで星の数ほどタイポっても大丈夫!(心が折れない限りは)

to restart at any time, enter rs

rs コマンドが必要になる場面はどのようなケースなのだろう?