'How to run a npm script on a deployed Heroku NodeJS app

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.



Solution 1:[1]

Yes:

$ heroku run npm run refresh

Solution 2:[2]

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.

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hunterloftis
Solution 2 Ruby_Pry
Solution 3