Search code examples
node.jsnodemon

Notify app.js if it run from "npm run dev" or "npm start"


Is that possible to notify app.js file or any other file that I am using a specific script from package.json? my relevant scripts

"dev":"nodemon app.js",
"start":"node app.js"

In my case i have cron functions that run on background, its a problem when I using nodemon and some of those function invoked I kill them before them ended.

on other way , its more convenient to use nodemon on development, so i want to know if there is a way to notify my app.js if it run from "npm start" or "npm run dev"


Solution

  • What about using arguments ?

    "dev":"nodemon app.js dev",
    "start":"node app.js production"
    

    process.argv holds a list of all arguments, including dev and production now which can then be used to distinguish the two cases.