I'm learning Node.js, my demo has two files:
/server.js
/public/index.html
/server.js
will get /public/index.html
and then return to the client.
I'd like to use nodemon
to auto reload when /public/index.html
is modified. However, it seems like nodemon
only works when I modify /server.js
and not when /public/index.html
is modified.
I'm using nodemon server.js
to starting the server.
Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.
When Nodemon restarts the ExpressJS server on changes, Livereload recreates the server and sends to the browser a refresh command when connected liveReloadServer. refresh("/"); . app.
Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.
Just specify watching html
on the nodemon
command line (or better yet, add a config file).
From the documentation:
By default, nodemon looks for files with the .js, .coffee, .litcoffee, and .json extensions. If you use the
--exec
option and monitor app.py nodemon will monitor files with the extension of .py. However, you can specify your own list with the -e (or --ext) switch like so:
nodemon -e js,jade
Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .jade.
Add nodemon.json
configuration file worked for me.
{ "ext": "html" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With