Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemon not restarting when html file is modified

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.

like image 644
Hom nom nom nom ... Avatar asked Jun 09 '16 16:06

Hom nom nom nom ...


People also ask

How do I restart Nodemon restart?

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.

Can Nodemon refresh browser?

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.

Why Nodemon is not working?

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.


2 Answers

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.

like image 183
Traveling Tech Guy Avatar answered Sep 20 '22 01:09

Traveling Tech Guy


Add nodemon.json configuration file worked for me.

{   "ext": "html" } 
like image 33
Long Nguyen Avatar answered Sep 22 '22 01:09

Long Nguyen