Track yaml file changes in nodemon
Asked Answered
I

5

6

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

Incommunicative answered 16/1, 2020 at 20:12 Comment(0)
B
7

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.

Bendicta answered 16/1, 2020 at 22:11 Comment(1)
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.Cochlea
E
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"
}
Etsukoetta answered 28/1, 2021 at 22:1 Comment(1)
Nice! Only option that worked for me trying to watch .env files.Howey
B
7

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.

Bendicta answered 16/1, 2020 at 22:11 Comment(1)
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.Cochlea
C
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

Cytogenetics answered 16/1, 2020 at 20:31 Comment(4)
you mean --extBendicta
try nodemon --help, I see -e --ext and -x --exec.Bendicta
yeah they might have made a mistake in the github docs you can make a pull request :DCytogenetics
the github doc doesn't say --exec for -e but the sentence is ambiguous. You should try to format your answer and add some documentation about the flag for completeness and you'll have some upvotesBendicta
N
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.

Nickname answered 28/8, 2020 at 9:32 Comment(0)
W
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.

Weltpolitik answered 20/7, 2020 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.