Running DNX apps with nodemon

Very quick, as much a note for myself as anything else.

There’s a Node package called nodemon which monitors files and restarts processes; it’s primarily used to watch .js files and restart Node applications when they change.

You can use it with any file extensions and commands, though, which means you can use it to monitor .cs files and restart DNX applications when they change. It also stops Kestrel when you (reflexively) hit Ctrl-C, which often makes Kestrel on its own hang.

I’ve set up this Bash function to do this on my machine:

dnxmon () {
  nodemon -e cs,json -x "dnx ${1-$DNX_DEFAULT_DIR} ${DNXMON_CMD}"

I used to use an alias, but it wouldn’t let me change the directory passed to dnx and I’ve been finding that useful. If you want, you can also change the DNXMON_CMD variable to run a command other than kestrel.

Share on facebook
Share on google
Share on twitter
Share on linkedin


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.