Here's my code for an express server:
const express=require('express');
express();
const app=express();
app.get('/',(req,res)=>{
res.send('Welcome to API xyz!');
});
app.listen(3000,()=>{
console.log('Listening on port 3000...');
});
Running the server from a git bash terminal, in the app's directory, using:
nodemon index.js
initially gives the message:
[nodemon] starting `node index.js`
Listening on port 3000...
Whenever I save a change to the output of res.send()
as follows:
res.send('Welcome to API abc!');
and save the index.js file, I get this message:
[nodemon] restarting due to changes...
but I do not get the console.log()
text, and when I reload localhost:3000
in Chrome, I still get the output:
Welcome to API xyz!
How can I get the server to update in response to saved changes without having to stop nodemon and restart it (which is the whole point of running nodemon in the first place)?
EDIT: I noticed that when nodemon restarts, I get:
restarting due to changes...
but I don't get
starting `node index.js`
after that. I only get
starting `node index.js`
when I first run nodemon.
EDIT 2: thinking that maybe this is related to the same issue that other nodemon users have experienced, as noted here in its Github issues log?
files triggering change check: index.js
matched rule: **\*.*
changes after filters (before/after): 1/1
restarting due to changes
index.js
– Roughandtumble"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon server.js" },
– Gwenny