4
5

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.

【Express4】pm2でwatchができない時の対処法

Last updated at Posted at 2015-04-28

問題

ファイルを編集・更新したら、手動でnodeコマンドを打たなくても自動で更新されるようにpm2を使ってwatchする

以下のコマンドで


$ pm2 start bin/www --watch


がしかし、public以下は編集するとちゃんと反映されるが、routesとviewsはダメだった。
app.jsやroutes以下のjsファイルも監視してくれなくてハマった。

node-devを使ってみる

インストールして


$ npm install node-dev -g

package.jsonを修正する

package.json

  "script":{
    "start" : "node-dev ./bin/www"
  },

うまくwatchできた

一度起動したプロセスを削除して、この状態で再度やってみると


$ pm2 start bin/www --watch

うまくwatchできた。

他の方法でも

pm2を使わないでやるなら、シンプルにnode-devだけでもできる。開発の段階ではこれで十分。

package.json

  "script":{
    "start" : "node-dev ./bin/www"
  },

として、


$ npm start

でもwatchできる。

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?