chovy
chovy

Reputation: 75844

is there anything like nodemon that will restart a node app when .ejs file changes?

is there anything like nodemon that works on .ejs file changes?

nodemon will detect changes in .js or .coffee files and restart your node app. But it won't detect changes to view files. I've emailed author, but they are unresponsive.

Upvotes: 26

Views: 24412

Answers (6)

Stanley Ulili
Stanley Ulili

Reputation: 1424

If you are using Node.js v18 or higher, you can stop using nodemon and just pass the --watch flag to the node command:

node --watch index.js

The option is still experimental, but it works fine most of the time.

Upvotes: 4

Emanovwe Emmanuel J
Emanovwe Emmanuel J

Reputation: 49

Just make sure your NODE_ENV=development and use nodemon. It works

Upvotes: 0

lkg
lkg

Reputation: 876

You can use supervisor. https://github.com/isaacs/node-supervisor or npm install supervisor -g

If you need to watch certain files, you just update the -e argument. So you would run something similar to

supervisor -e 'js|ejs|node|coffee' app.js 

Upvotes: 20

Will
Will

Reputation: 4631

Maybe this wasn't implemented when you posted the question, but you simply pass the option

-e coffee,js,ejs

See the docs: https://github.com/remy/nodemon

supervisor is an alternative, but when I last used it, it was eating CPU. That may have been fixed by now, but I'd stick with nodemon.

Upvotes: 43

Maciej Jankowski
Maciej Jankowski

Reputation: 2834

use this in your packages.json

"scripts":{
"start":"nodemon -e js,ejs,html -w . -w public -w views -w routes -w models server.js"
}

Supervisor constantly eats ~20% of my CPU

Upvotes: 11

Vadim Baryshev
Vadim Baryshev

Reputation: 26219

  1. You can wrap ejs with self-written monitor that will watches for file changes and clear template cache.
  2. You can change template engine to one that alredy support hot-reloading. I recommend you ECT. It support automatic template reloading from the box (with watch option) and several times faster than EJS and many others.

Upvotes: 1

Related Questions