Running locomotivejs app on heroku

607 views
Skip to first unread message

Alex Brown

unread,
Jun 11, 2012, 10:58:06 AM6/11/12
to locomo...@googlegroups.com
Does anyone have any info on how to get an app using LocomotiveJS running on heroku, since there's no server.js or app.js to point to in my package.json file?

Alex Brown

unread,
Jul 1, 2012, 7:30:44 PM7/1/12
to locomo...@googlegroups.com
anybody?

Jared Hanson

unread,
Jul 1, 2012, 7:47:32 PM7/1/12
to locomo...@googlegroups.com
Alex -

This hasn't been fully documented yet (obviously), but check out the server.js file (which implements `lcm server`), here:

    locomotive.boot(dir, env, function(err, server) {
      if (err) { throw err; }
      server.listen(port, address, function() {
        var addr = this.address();
        debug('listening on %s:%d', addr.address, addr.port);
      });
    });

Locomotive exposes a `boot` function that takes a directory and an environment (production, development, etc), and calls back with a fully configured Express server, which can be told to listen wherever.

You can use that to write a server.js file that Heroku can launch.

Cheers,
Jared
--
Jared Hanson <http://jaredhanson.net/>

Alex Brown

unread,
Jul 11, 2012, 11:33:38 AM7/11/12
to locomo...@googlegroups.com
Sorry to be a pain, do you have an example?
I'm keen to use this locally with nodemon too if possible..?

Alex

David Roncancio

unread,
Jul 15, 2012, 1:03:05 PM7/15/12
to locomo...@googlegroups.com
Yup working on the same stuff and got to the point where dont know how can the mongoose initializer figure out the where is dev or prod enviroment to connect to either database, on the heroku im trying 

web: NODE_ENV=production lcm server

on the Procfile, which should probably launch it but i havent test it

Jared Hanson

unread,
Jul 15, 2012, 1:08:30 PM7/15/12
to locomo...@googlegroups.com
Right now, Locomotive is loading config/initializers and then config/environments.  I'm thinking that it'd be best (especially for PaaS hosts like Heroku), to swap that, load environments and then initializers.  Would that help?

As a workaround, initializers should be able to do NODE_ENV checks:

   if (process.env.NODE_ENV == 'production') { ... }

Jared

David Roncancio

unread,
Jul 15, 2012, 2:25:46 PM7/15/12
to locomo...@googlegroups.com
heya,

Yup i think loading enviroments and then initializers would be the best, i usually do that when doing bare express, load the enviroments and the db-uri and then initialize the connection with db-uri independant of enviroment, thank you for the workaround gonna try it, 

Alex Brown

unread,
Jul 15, 2012, 2:28:05 PM7/15/12
to locomo...@googlegroups.com, locomo...@googlegroups.com
Would you mind forking / putting the server.js or whatever you're working with on github / as a gist so I can see how you are doing it?

Cheers

David Roncancio

unread,
Jul 16, 2012, 12:57:20 AM7/16/12
to locomo...@googlegroups.com
Sure, let me get it organize it because its is breaking on the db connection :S

Alex Brown

unread,
Aug 2, 2012, 5:41:23 AM8/2/12
to locomo...@googlegroups.com
any update on this?
I created an issue on github


On Monday, 11 June 2012 15:58:06 UTC+1, Alex Brown wrote:

Alex Brown

unread,
Aug 6, 2012, 10:33:41 AM8/6/12
to locomo...@googlegroups.com
Is this project actively developed?
Considering using it, but wary of seemingly stagnant development on it...

Jared Hanson

unread,
Aug 6, 2012, 10:59:48 AM8/6/12
to locomo...@googlegroups.com
Locomotive is a personal project primarily developed by myself, with contributions from a couple other people (@gothack primarily, many thanks!).  It is certainly still under active development.  That said, because it is a personal project at this point, its priority goes up and down based on what other projects it is competing with for time.  And right now, another project is in crunch mode (which may give the temporary appearance of somewhat stagnant development on Locomotive).

My typical recommendation to anyone evaluating open source projects, including Locomotive, is this: read and evaluate the code.  If it is as good as or better than something you could develop in-house, use it.  If it meets those criteria but lacks features, use it and contribute the features you need.

At some point, Locomotive's feature set will be such that many people can adopt it without ever needing to contribute.  However, because the project is still very young, that requirement is going to come up quite often.

Regarding your issue specifically, I don't personally use Heroku as a deployment platform, so that's why the support is lacking.  It should be easy to implement, and I've posted some suggestions on this forum, but its not an near-term priority for myself to personally implement and verify.  That said, I gladly encourage and accept patches!

Cheers!
Jared

Alex Brown

unread,
Aug 6, 2012, 12:29:43 PM8/6/12
to locomo...@googlegroups.com
Sorry..
I understand. I maintain a couple of OS projects myself, and know it is difficult!

Anyway..
I've played around, and I've got 2 results.

First:
This works as a server.js file

However:
As it turns out, you actually don't need it!

you simply set your Procfile (required for apps hosted on Heroku) to execute lcm server!
I'll do a write up in the wiki

Caveat:
This will only work if the following pull request is merged in:

(one line change)

Alex

Alex Brown

unread,
Aug 6, 2012, 12:39:54 PM8/6/12
to locomo...@googlegroups.com
Can't see how to add a page to the wiki (don't have access I suspect)
What should I do?

Alex

Jared Hanson

unread,
Aug 6, 2012, 1:12:00 PM8/6/12
to locomo...@googlegroups.com
Many thanks!  The wiki is now publicly editable.

I'll do my best catch up on pull requests and get this merged in the next few days.

Jared

Alex Brown

unread,
Aug 6, 2012, 6:20:38 PM8/6/12
to locomo...@googlegroups.com
Great, that would be really helpful if you could.
I'll do the wiki page as soon as you merge in that particular pull request.

Jared Hanson

unread,
Aug 8, 2012, 1:29:48 AM8/8/12
to locomo...@googlegroups.com
Alex -

I copied over the relevant changes for grabbing the port from the environment.  It's in master now.  I'm holding off a bit on the file extension stuff until I can review it further (but I don't think that's required for Heroku support anyway).

Jared

Alex Brown

unread,
Aug 8, 2012, 8:04:13 AM8/8/12
to locomo...@googlegroups.com
Yeah...
That file extension stuff was just to close one of the issues on github..

Wanted to do it to allow either/or... so can do it either way
I must say, i prefer not having to use .html.ejs myself, but that's preference i guess
Reply all
Reply to author
Forward
0 new messages