6

Nodemon does not reload after yaml files change. How can I configure nodemon to reload the server when a yaml file changes?

Rumesh Madhusanka
  • 1,105
  • 3
  • 12
  • 26

5 Answers5

10

nodemon can also be configured using a config file.

Create a file named nodemon.json and place it in the root of your project, for example where your project's package.json file already is.

If you want to add .yaml to the default extensons watched, put this code in your nodemon.json

{
  "ext": ".js, .mjs, .coffee, .litcoffee, .json, .yaml"
}
Alex Baban
  • 11,312
  • 4
  • 30
  • 44
6

You can configure nodemon to watch your yaml files in two ways:

  1. By extension
  2. With the file path

By Extension

The documentation states that:

By default, nodemon looks for files with the .js, .mjs, .coffee, .litcoffee, and .json extensions.

You can specify your own list with the -e (or --ext) switch

Like so:

nodemon -e yaml server.js

Note: the dot before the extension .yaml is not mandatory, you can omit it.

Now when any .yaml file changes, your server will restart.


With the file path

You can use the flag -w (or --watch)

The wiki says:

Watch directory "dir" or files. use once for each directory or file to watch.

Like so:

nodemon -w file1.yaml -w file2.yaml server.js

You'll see something like

[nodemon] watching: file1.yaml file2.yaml

Now when one of these two files changes it will restart, but it wont' watch another .yaml file if it is not specified.

Community
  • 1
  • 1
Mickael B.
  • 4,755
  • 4
  • 24
  • 48
  • This extension flag prevents nodemon from watching unnecessary source code files that may not affect a running node.js script, but you can customize it as you want. – Fabio Martins Feb 03 '20 at 20:55
2

With the -e option you can listen to the changes of most file extension. It is shorthand for --ext as pointed out in the comments.

nodemon -e .yaml index.js

C.Gochev
  • 1,837
  • 11
  • 21
1

As per documentation,

By default, nodemon looks for files with the .js, .mjs, .coffee, .litcoffee, and .json extensions. However, you can specify your own list with the -e (or --ext) switch like so:

nodemon -e js,pug

Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .pug.

Nishant Shah
  • 2,022
  • 22
  • 20
0

I case you want to watch/track for multiple file types, like .ts and .yaml do this

nodemon -e ts -e yaml

this will not only watch changes for typescript files but also for yaml files.

and in case your compiled build contains yaml files you have to ignore that files from nodemon to watch otherwise it will get into the loop of compiling and watching the same files indefinitely, so use this

nodemon -e ts -e yaml --ignore build/ considering build is the directory(in the same directory where package.json file is present) where the compiled typescript files and other files resides.

Mohit Malik
  • 691
  • 2
  • 6
  • 11