11

Under scripts in package.json I have the following.

'refresh': node refresh db

Is there a way to trigger this particular npm script on a NodeJS app deployed on Heroku.

aksanoble
  • 2,480
  • 4
  • 18
  • 19

3 Answers3

29

Yes:

$ heroku run npm run refresh
hunterloftis
  • 13,386
  • 5
  • 48
  • 50
  • Sort of, but not quite - this will run in a one-off dyno, not on the same dyno(s) used to access the running app. – Tim Malone Aug 01 '17 at 02:23
  • 5
    This answer is accurate. The question was not how to execute a script on a specific dyno, but how to execute one on a specific app. An app is made up of n ephemeral dynos on Heroku by design. – hunterloftis Aug 01 '17 at 13:45
1

Per the Heroku Node.js Documentation, you can add pre and post install scripts. In addition, you can add scripts that can be triggered by environment variables.

Ruby_Pry
  • 237
  • 1
  • 10
  • Yes, I have added a postinstall and start scripts but is there a way to trigger a npm script after the deploy is done? In my case I need to refresh the db on a need basis. – aksanoble Jul 25 '16 at 15:57
  • It would help if you could provide more details on what conditions will trigger this script. – Ruby_Pry Jul 25 '16 at 16:43
0

You can also do this using only the browser; Just log in to manage your app in the heroku dashboard (https://dashboard.heroku.com/apps/[app_name]) and there click on the right side of it: More > Run console

Then you can run any command: command line in heroku

https://devcenter.heroku.com/changelog-items/1137

Shlomo
  • 120
  • 2
  • 8
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '22 at 14:46