0

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"

2
  • Your approach is not correct. The application must not know anything about who starts it. Use different configuration files for the two cases: production (npm start) and development/debug (npm run dev) and pass the name of the configuration to use either as a command line argument or (better) in an environment variable. The standard environment variable NODE_ENV is usually used to tell apart these situation. Its values would be production and development. nodejs.dev/en/learn/… Commented Dec 27, 2022 at 19:55
  • im not sure i understand you, can u explain more with example please? Commented Dec 27, 2022 at 20:14

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.