Nodemon does not reload after yaml files change.
How can I configure nodemon to reload the server when a yaml
file changes?
You can configure nodemon to watch your yaml
files in two ways:
- By extension
- 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.
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"
}
You can configure nodemon to watch your yaml
files in two ways:
- By extension
- 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.
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
--ext
–
Bendicta nodemon --help
, I see -e --ext
and -x --exec
. –
Bendicta --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 upvotes –
Bendicta 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.
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.
© 2022 - 2024 — McMap. All rights reserved.