Recognize if nodemon is started first time, not restarted
If you want in your js app to somehow recognize that it’s first time when nodemon starts (and not a restart due to script change), you might use this experimental (not reliable) solution.
package.json place such content:
"MYSTART": "node app/app.js",
"preMYSTART": "node -e \"const fs=require('fs'); fs.writeFileSync(__dirname + '/pre_firstrun_flag','')\""
prephrase there is for reason, it’s constant for node. so whatever you name your script (i.e.
MYSTART) you should just add
prein front of it, so that command will be pre-run automatically when you run
npm run MYSTART
2) next, in your script you can detect with
const isFirstRun = fs.existsSync( 'path/to/root/pre_firstrun_flag');
if (isFirstRun) fs.unlinkSync('path/to/root/pre_firstrun_flag');