---
id: 2987
title: Hacks to get Loopback App's running on Heroku
slug: hacks-to-get-loopback-apps-running-on-heroku
date: '2015-03-27T10:52:28Z'
modified: '2015-03-28T03:59:43Z'
status: publish
type: post
author: pmoelgaard
categories:
  - undocumentation
tags:
  - Heroku
  - Loopback
  - NodeJS
excerpt: null
canonicalPath: /posts/hacks-to-get-loopback-apps-running-on-heroku
featuredImage: null
commentCount: 3
wordCount: 176
readingTimeMinutes: 1
hasMedia: false
hasVideos: false
url: >-
  https://forwardthinking.pemo.me/posts/hacks-to-get-loopback-apps-running-on-heroku
---
To get Loopback App's running on Heroku, a couple of hacks are required due to the way Loopback manages it's configurations. The first issue to solve is to get Loopback to take the port number from the environment since Heroku uses arbitrary port numbers to target different applications. There is probably a more elegant way, however I first wanted to stay out of node\_modules files, so I opted to just focus on modifying server.js. It's actually very easy, since loopback internally supports passing arguments to the listen function all the way out from the server.js file. It does this by switching between automatic configuration and explicit configuration from the arguments passed to the listen function. So, basically it's just amending the "start" function to fetch the port number from the environment and pass it as argument to the listen function. I have done it this way...

app.start = function () {
   // start the web server
   var port = process.env.PORT || 8000;
   return app.listen(port, function () {
      app.emit('started');
      console.log('Web server listening at: %s', app.get('url'));
  });
};
