Skip to content

Instantly share code, notes, and snippets.

@TomV
Last active May 28, 2024 15:02
Show Gist options
  • Save TomV/5680864 to your computer and use it in GitHub Desktop.
Save TomV/5680864 to your computer and use it in GitHub Desktop.
Simple Terminal for Locomotive!
/**
* Simple script to invoke locomotive
* uses the jake-lcm module: https://npmjs.org/package/jake-lcm
*
* Just put this at the root of your locomotive app
*
* Date: 5/30/13
*
*/
var lcm = require('jake-lcm')
, repl = require('repl');
// More about jake-lcm here: https://github.com/drudge/jake-lcm
lcm.exec(
{
initializers: ['00_generic', '02_mongoose', '03_models']
},
function () {
repl.start({
prompt: "Locomotive: > ",
input: process.stdin,
output: process.stdout
});
}
);
@TomV
Copy link
Author

TomV commented May 30, 2013

Here's a quick example of using it:

In my 00_generic initializer I set up a global container, myapp:

    var myapp = global.myapp = {};
    myapp.set = this.set.bind(this);
    myapp.root = process.cwd();
    ....

In the example above, I just loaded the 03_models initialzier, so now I can create and test a user:

  Locomotive: > User = myapp.User

That dumps the whole mongoose User object to the terminal, so you can do this instead:

  Locomotive: > User = myapp.User; "done"

Next, create a user in the terminal:

  Locomotive: > test_user = new User({ email: 'test@example.com', display_name: 'Joe Tester'});
  { email: 'test@example.com',
    display_name: 'Joe Tester',
    _id: 51a7d082a99457d42f000002,
    balance: 0,
    status: 'offline',
    password_salt: '5e69ffpbac1y8pvi',
    created_at: Thu May 30 2013 15:19:46 GMT-0700 (PDT),
    roles: [ 'user' ] }
  Locomotive: > 

Works pretty well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment