Heroku, Express & Node Bug – 500 TypeError: Object # has no method ‘randomBytes’

I decided I needed to write a post about this error, because the solution took me forever to find, so hopefully some poor soul stumbles across this and doesn’t waste as much time on this as I had to.

Basically if you get a nasty error output from your app when it is live on heroku, the first step is to type “heroku logs” into your terminal. This command pulls your app’s HTTP logs and spits it on screen.

Here was what I recieved:

Error: Can’t use mutable header APIs after sent.

[web.1]: at app/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js:64:17
[web.1]: at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
[web.1]: at ServerResponse.<anonymous> (/app/node_modules/express/node_modules/connect/lib/middleware/logger.js:149:20)
[web.1]: at generate (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:288:13)
[web.1]: at [object Object].<anonymous> (fs.js:107:5)
[web.1]: at wrapper (fs.js:245:17)
[web.1]: TypeError: Object #<Object> has no method ‘randomBytes’
[web.1]: at ServerResponse.getHeader (http.js:543:11)
[web.1]: at [object Object].emit (events.js:61:17)
[web.1]: at Object.session [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:297:7)
[web.1]: at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
[web.1]: throw new Error(“Can’t use mutable header APIs after sent.”);
heroku[web.1]: Process exited with status 1
[web.1]: at Object.methodOverride [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:37:5)
app[web.1]: ^
app[web.1]: at ServerResponse.<anonymous> (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:277:36)
[web.1]: at Object.uid (/app/node_modules/express/node_modules/connect/lib/utils.js:117:17)
[web.1]: at Object.cookieParser [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5)

While this isn’t the most useful error output, at least to me, some extensive google searching told me that this happens as a result of incompatible Framework versions. Essentially my version of Express was attempting to call methods that don’t exist on the default version of Node.js that Heroku provides.

The Fix! You can read here. Basically you need to specify which version of Node.js you want Heroku to use with your app. I have no porting issues at this point, so I’ve opted for Node.js 0.8.x.

Hope that helps someone, happy devving!

Increase SEO by Linking Your G+ Account To Your Web Pages

One of the first tasks I was responsible for at Mover is linking our blog post articles to our Google Plus profiles. By doing this, Google can then index our search results using verified authors giving our posts greater credibility. Furthermore, the micro-profile of the author will show up under any indexed search results that they are the other of. This feature was released in the middle of 2012.

This is a very simple process:

1) Link to your G+ profile on your web page, and include a ref=”author” tag:

<a href=”[URL TO G+ PROFILE]” ref=”author”>Your Name</a>

Adding ref=”author” informs Google’s web crawlers that they should include the author in search results.

2) Edit your Google Plus Account

To complete the authentication loop, Google will examine your profile to see if you are indeed a contributor, preventing you or others from falsely linking authors to posts or articles. You can update your “contributions” by clicking this link.

Finally, verify that Google’s article profiler can index your newly added author information properly be entering the URL of your site into this tool: http://www.google.com/webmasters/tools/richsnippets