LoginSignup
0
1

More than 5 years have passed since last update.

[Node.js][PM2] Vagrant 共有フォルダのファイルを watch する方法

Last updated at Posted at 2018-11-28

宮崎在住エンジニアのジョウ(@JotarO_Oyanagi) です。

Vagrant を Node.js の実行環境として使用していて、ホットリロードとして PM2(Node アプリをデーモン化してくれる)の watch を使う場合、普通の設定だとホットリロードが効かないので、その解決策メモです。

TL;DR

  • 環境:centos 7.5, node 8.11.4
  • pm2 startecosystem.config.js または config.json を使用して実行
  • watch_optionsusePolling: true を設定

書き方の例

ecosystem.config.js
module.exports = {
  apps : [{
    name: 'MyApp',
    script: 'app.js',
    watch: true,
    watch_options: {
      usePolling: true
    },
    env: {
      NODE_ENV: 'development',
      name: 'MyApp_dev',
      PORT: 3000,
      TZ: "Asia/Tokyo"
    }
  }]
};
config.json
{
  "name": "MyApp",
  "script": "./app.js",
  "watch": true,
  "watch_options": {
    "usePolling": true
  },
  "env": {
    "NODE_ENV": "development",
    "name": "MyApp_dev",
    "PORT": 3000,
    "TZ": "Asia/Tokyo"
  }
}

これだけです。カンタンですね!

終わりに

色々探し回った結果、これだけでよかったのかよ!という複雑な気持ち。

0
1
2

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