Need Changes while restarting server for file changes

So in heroku I have observed that they have a option to build the development code to production code by using npm run heroku-postbuild and then executes npm start so that whenever user opens the webpage the server wont build the code one again and start the server instead it will directly start the server.
So if there was something like whenever there are changes in files the app should execute:

npm run build && npm start

And when user hits website it should only execute :

npm start (and not npm run build)

Because when you use react scripts or webpack it takes time to build the code and then start the server so it is better to have it like that i mentioned.
I think you could give the option of executing what by using watch.json

Yes, you’re right, you can currently do that using watch.json! It’s called “install” rather than “build”.

To control the patterns of which files (such as, by default, package.json) when they are changed changed cause “install” to be run, and which files (such as, by default, *.js) when they are changed cause “start” to be run, you can edit watch.json - an example is here:!/watch-json?

Hope this helps,


so if i want to run a bash command like ‘npm run build’
What could i enter in watch.json

Will this work :

“install”: {
“include”: [
“restart”: {
“exclude”: [
“include”: [
“throttle”: 5000

Yes, but you would also want your package.json to contain something like this.

  "scripts": {
    "install": "npm run build",
    "build": "bash",
    "start": "node server.js"

I don’t know precisely how your project is set up.

Hope this helps,


Heyy I didnt get you
I hope you understand what I want
See basically glitch starts server it executes npm start. But I want to execute command npm run build && npm start
When I make changes to the files and folders
But after 15minutes the website goes to sleep after that when a user hits the website i want the server to restart by npm start(npm run build should not get executed)