I have an express app. I am using swig as the template engine. Is it possible to reflect my HTML changes in the browser when I click refresh. I don't want to restart the server every time I need to do a HTML change?
We can render them directly into our server by specifying the response to send when the default route is accessed. const express = require("express"); const app = express(); app. listen(3000, () => { console. log("Application started and Listening on port 3000"); }); app.
nodemon is a tool that helps develop Node. js based applications by automatically restarting the node application when file changes in the directory are detected. nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for node .
Add Start Script in pacakge. It's time to check how does nodemon is working in our app, open the terminal and start the app using the following command: nodemon server. js # [nodemon] 1.19. 1 # [nodemon] to restart at any time, enter `rs` # [nodemon] watching: *.
I got the solution from this link.
I installed supervisor module as global installation
npm install supervisor -g
I stated my app like this
supervisor -e html,js app.js
Here i am specifying to watch the changes in files with extensions .html and .js. So when these files are changed its automatically reloaded when the next request comes.No restart required.
There are plenty of tools for this:
And I'm sure you could find more.
You can simply disable swig's caching:
if (process.env.NODE_ENV !== 'production') {
swig.setDefaults({ cache: false });
}
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