Nodemon not restarting when html file is modified
Asked Answered
O

6

38

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.

Outlawry answered 9/6, 2016 at 16:1 Comment(0)
S
42

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.

Szymanski answered 9/6, 2016 at 16:5 Comment(4)
Just to add to this, since you've made mention of using a nodemon.json file, here's the sample config from the docs. You can use the ext property to specify which file extensions to watch.Bunker
nodemon -e * will force it to watch for ALL file changes in the folder.Caravansary
it rebuilds, but doesnt refresh the browser pageAgog
nodemon -e '*' for me. Without quotes, bash provides file from my current directoryHeroics
B
17

Add nodemon.json configuration file worked for me.

{
  "ext": "html"
}
Benevolent answered 19/6, 2018 at 7:58 Comment(0)
B
16

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

{
    "ext": "js,html"
}
Bounce answered 30/9, 2019 at 12:49 Comment(1)
Or if running from command line, nodemon -e js,html app.jsIsolecithal
H
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.

Hague answered 3/6, 2021 at 17:6 Comment(0)
D
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.

Depositor answered 23/4, 2020 at 16:43 Comment(0)
S
1

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

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

Restart nodemon, that works with me.

Sharonsharona answered 9/5, 2018 at 21:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.