How to run a npm script on a deployed Heroku NodeJS app
Asked Answered
F

3

12

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.

Faa answered 25/7, 2016 at 15:6 Comment(0)
A
29

Yes:

$ heroku run npm run refresh
Annalisaannalise answered 25/7, 2016 at 17:48 Comment(2)
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.Hamann
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.Annalisaannalise
B
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.

Batholith answered 25/7, 2016 at 15:42 Comment(2)
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.Faa
It would help if you could provide more details on what conditions will trigger this script.Batholith
Y
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

Yawn answered 19/4, 2022 at 11:3 Comment(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.Yearround

© 2022 - 2024 — McMap. All rights reserved.