From xradiograph

WebDevelopment: Heroku
Deploying with Git


See What The Code Behind An App Does With Just One Click


Publish your app online using Heroku - covers node.js, static pages, and php (!). - Darius notes he deploys on Heroku [which] is free for Twitter bots. The way it works is every app gets one free process (or “drone”). Each twitter bot only requires one process to run, so it’s free. (no technical notes present.)


Heroku and SOA
Heroku isn’t for idiot (2012)



Heroku is a “cloud” provider, but there are tools to make interaction easier:




Heroku’s free plan limits the number of database rows that you can have to 10,000.
So, let that be known.
TODO: citation needed


TODO: also free hours keeps changing.
Solution: do NOT run your bot on an internal setTimeout - that keeps things running ALWAYS
rather, use Heroku’s scheduled tasks. The atomicity of the scheduling could be better - but the price is right.



Rolling back releases - easy to work with
heroku releases
heroku rollback v40 to roll back to v40
The rollback itself will become a release, but it’s clearly noted.



Working with NodeJs


Publishing/starting an app

  1. heroku login
    1. if you get a lot of weird errors, you probably have a bad uname/pword combo
  2. heroku create <optional: app-name>
    1. If you don’t provide an app-name, one will be auto-generated
  3. rename (if you need to)
    1. max of 30 characters
    2. heroku apps:rename <newname>
  4. git push heroku master
  5. heroku ps:scale worker=1 (or web, as the case may be)


also: heroku restart if things get hinky.


If you’re working with a local branch that is not itself master, then use git push heroku <local-branch>:master
For instance, I have a master branch that is for node locally, a gh-pages branch that has a web-frontend, and a heroku-branch that has code for pushing to tumblr.



Specifying a Node.js version

Specifying a Node.js version
Make sure it’s correct in your package.json file.
Running foreman locally will use your local node install.
But heroku will use the specified version (UNK what the default is).
I had a problem where I copied a package.json file with an old node version in it, ignored it, and the app failed when I used some ES6 terms that were only supported under 4.x
Once I updated and committed package.json everything worked fine.


2016-03-30T12:10:51.465747+00:00 app[scheduler.5173]:     logger(`s1: ${s1} \ns2: ${s2}`);
2016-03-30T12:10:51.465756+00:00 app[scheduler.5173]:            ^
2016-03-30T12:10:51.465757+00:00 app[scheduler.5173]: SyntaxError: Unexpected token ILLEGAL
2016-03-30T12:10:51.465765+00:00 app[scheduler.5173]:     at Object.Module._extensions..js (module.js:478:10)
2016-03-30T12:10:51.465758+00:00 app[scheduler.5173]:     at Module._compile (module.js:443:25)
2016-03-30T12:10:51.465758+00:00 app[scheduler.5173]:     at exports.runInThisContext (vm.js:73:16)
2016-03-30T12:10:51.465766+00:00 app[scheduler.5173]:     at Module.load (module.js:355:32)
2016-03-30T12:10:51.465767+00:00 app[scheduler.5173]:     at Function.Module._load (module.js:310:12)
2016-03-30T12:10:51.465767+00:00 app[scheduler.5173]:     at Module.require (module.js:365:17)
2016-03-30T12:10:51.465767+00:00 app[scheduler.5173]:     at require (module.js:384:17)
2016-03-30T12:10:51.465769+00:00 app[scheduler.5173]:     at Object.<anonymous> (/app/index.js:7:37)
2016-03-30T12:10:51.465768+00:00 app[scheduler.5173]:     at gunmyth (/app/gunmyth.js:8:20)
2016-03-30T12:10:51.465769+00:00 app[scheduler.5173]:     at Module._compile (module.js:460:26)
2016-03-30T12:10:52.354027+00:00 heroku[scheduler.5173]: Process exited with status 1





heroku addons:create scheduler:standard

[boilerplate output]

heroku addons:open scheduler


While the docs I’ve read talk about creating a shell script, if your app is set to execute when run without parameters, you can you that in your setup. Even with parameters, it should work, I would think.


Remember: the scheduler is using UTC, so adjust accordingly.


node index.js


NOTE: If your scheduled task is the only thing your application needs to do, you do not need heroku ps:scale worker 1 at all
Instead, heroku ps:scale worker 0
This assumes that the scheduled task is the only task in your application.
Which is what you might want for a bot, for example.


To do a one-off execution, use heroku run
E.h., heroku run node index.js


Storing keys in environment/config variables


heroku config:set KEY_NAME=keyvalue KEY_NAME_2=keyvalue2


View keys via heroku config or by logging in and going to app’s dashboard



How do I deploy to heroku from git when my API key is in a .gitignore file? :


use, and you can keep your secrets in a file called .env and ignore that in .gitignore


Install it with heroku plugins:install


You can run heroku config:pull --overwrite --interactive to generate an initial .env file that includes your service secrets, etc, and heroku config:push to save it, remotely.


heroku config:push -o or --overwrite to push new local values to the dyno. You don’t need to restart for these to be used.


I am assuming that you are using node, since your config file is javascript. To get the values in your .env file in node use process.env - Parse and load environment files (containing ENV variable exports) into Node.js environment


NOTE: these env-vars are for heroku, so running the app in plain old node will not work. You’ll have to run with foreman start worker|web (Worker, if it’s a headless app, but it really depends upon the Procfile).


Don’t forget to add .env to .gitignore, or you’ll leak your access tokens!


stefan @ suggests adding the values to the local environment, trying to read them first, and then reading heroku env as a fallback:


apikey = process.env.LOCALENV || process.env.HEROKUENV;


NOTE: not implemented in the below sample


Sample config file

// Put your own Twitter App keys here. See for more detail.
// if you see 'process.env.SOMETHING' that means it's a heroku environment variable
// heroku plugins:install
// and will only work with 'foreman start worker'
module.exports = {

    consumerKey:    process.env.consumer_key,
    consumerSecret: process.env.consumer_secret,
    accessToken:    process.env.token,
    accessSecret:   process.env.token_secret,

    postLive:       (process.env.post_live.toLowerCase() === 'true')





ERROR: ssh: connect to host port 22: Bad file number

git push heroku master
ssh: connect to host port 22: Bad file number
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


I believe that port 22 is blocked by the firewall at work.


There might be a new alternative:


heroku git:remote --http-git


Credential prompt (post-login)

Although I swear I didn’t need to do this at one location, at home I was prompted for credentials.
Credentials meant NO USERNAME, and API KEY for the password.
API_KEY is obtained via heroku auth:token


See for more.


Looks like this is caused by
I haven’t figured out how to temporarily deactivate it (and I’d only want it deactivated when pushing to heroku).

  1. heroku auth:token
  2. copy the token
  3. when prompted for credentials, leave username blank, past token into password


(re) connecting repo to heroku

If you’ve connected to heroku on one machine, but pull the repository somewhere else, you may have to reconnect to heroku.


  1. cd repo
  2. heroku login
    1. authenticate
  3. heroku git:remote -a <heroku-app-1234>
    1. if you don’t have it memorized, check your heroku dashboard


Q What about SSH keys?

When you login, heroku will check for SSH keys. If none exist on that machine, it will ask you to gen and add.




I can only see about 100 lines of logging, WTF?!?!?


heroku logs -n 1500 (per SO)



I have some links over @


heroku pg:reset DATABASE where DATABASE is the name of your database



NOTE: I have only built two apps using PostgreSQL, and have a loooon way to go. If I want to do anything complicated.


NOTE: the heroku page notes you should run psql locally.
So, do that, and write up the notes on keeping everything straight. ‘cause my configs will be annoying, again.


TODO: write up notes. I am running it locally for testing. HOORAY!



  1. one database per application
    1. AFAICT
  2. heroku addons:create heroku-postresql:hobby-dev
Creating foo-bar-1234... done, (free)
Adding foo-bar-1234 to weird-herku-name... done
Setting DATABASE_URL and restarting weird-heroku-name... done, v4
Database has been created and is available
! This database is empty. If upgrading, you can transfer
! data from another database with pgbackups:restore
Use `heroku addons:docs heroku-postgresql` to view documentation.
  1. info
> heroku pg:info
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 9.4.2
Created: 2015-06-09 20:38 UTC
Data Size: 6.4 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported



Canvas and Heroku



Renaming apps

Renaming apps is surprisingly easy. See notes @
I kept the original, randomly-named app names, which were interesting -- but after awhile I couldn’t remember what was what. So I checked out the heroku source, looked at what the code actually was (and discovered I had no meta-data like comments describing the code/project either, it seemed, except for the package.json file. BUT STILL.


Anyway, renaming was a breeze.


heroku apps:rename newname




heroku apps:rename newname --app oldname if you don’t want to checkout the code. However, your git remotes won’t be updated.


Apps stopped

My apps run twitter bots (So far).
On August 18, 2015 a bunch of them (not all) stopped.
I didn’t notice until mid-October (BECAUSE I AM A BAD BOT-PARENT?).


heroku restart didn’t do a thing.


I had to re-scale the worker via heroku ps:scale worker=1


There were no available logs that I could grab. damn.




Link Dump - logging can destroy performance



Heroku “deploy code” button for web-pages.



See Also

Programming.Bots - which has some specific notes. As of 2015.03 I’ve only used Heroku for bots (or tutorials).



Category Tags

hosting cloud

Retrieved from
Page last modified on September 08, 2016, at 11:47 PM