37

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.

peteb
  • 18,552
  • 9
  • 50
  • 62
Hom nom nom nom ...
  • 479
  • 1
  • 5
  • 14

6 Answers6

40

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.

Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
  • 3
    Just to add to this, since you've made mention of using a `nodemon.json` file, [here's the sample](https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md) config from the docs. You can use the `ext` property to specify which file extensions to watch. – peteb Jun 10 '16 at 15:13
  • 4
    `nodemon -e *` will force it to watch for ALL file changes in the folder. – James McCormack Jun 21 '18 at 16:30
  • 1
    it rebuilds, but doesnt refresh the browser page – SuperUberDuper Jun 14 '19 at 07:40
17

Add nodemon.json configuration file worked for me.

{
  "ext": "html"
}
Long Nguyen
  • 9,898
  • 5
  • 53
  • 52
15

Use a comma separated string to add multiple extensions in nodemon.json

{
    "ext": "js,html"
}
ajthinking
  • 3,386
  • 8
  • 45
  • 75
10

Here's another possibility: using your existing package.json file:

"name": "app",
"version": "1.0.0",
"nodemonConfig": {
  "ext": "js,html"
}

Just keep in mind nodemon will only be checking for .js and .html files from now on. You'll have to add your own files if you have more.

Zebiano
  • 373
  • 5
  • 13
2

Add watching extension for all in package.json file do something like with your scripts:

"scripts": {
    "start": "nodemon -e * app.js"
  }

This worked for me.

imrvasishtha
  • 99
  • 10
1

Add a nodemon.json file, inside the file do something like:

{
   “watch”  : [ “filename.html”]
}

Restart nodemon, that works with me.