ikemonn's blog

技術ネタをちょこちょこと

【Node.js】Vagrantとsupervisorでファイル更新後自動でプロセスを再起動させる

概要

  • Vagrantを使っており、ホスト側(Mac等)のファイルを変更したら自動でプロセスが再起動してほしい
  • nodemonだと-Lオプションでできるが遅いらしい

  • supervisorをつかって、ホスト側のファイルを変更したら自動で変更されるようにする

手順

$ vagrant ssh$ npm i -g supervisor

package.jsonのscriptsのstartを編集

【旧】

"scripts": {
    "start": "node ./bin/www"
  },

↓ 【新】

"scripts": {
     "start": "supervisor -i views,public ./bin/www"
  },
$ npm start

参考

Vagrant+node.js+express4+MongoDBで簡単なWebアプリを構築