Narcissistic Preening Monarch

    herokuRun

    0.0.8 • Public • Published

    Heroku Run

    Build Status

    Simple module that allows to run commands on one-off heroku dynos from within the node applications. May beused for task automation.

    How to nstall

    $ npm install herokuRun --save

    How to use

    Run simple command (demo/command.js):

    var herokuRun = require( 'herokuRun' ),
        runner = herokuRun( 'token', 'my-app-name' );
     
    runner.run( 'pwd && ls', function( err, logger ) {
     
            if ( err ) {
             console.log( err );
             return;
            }
     
            logger
                .on( 'connected', function( auth ) {
                    console.log( 'connected' );
                    console.log( (auth) ? 'authorized' : 'unauthorized' );
                })
                .on( 'data', function( data ) {
                     process.stdout.write( data.toString() );
                })
                .on( 'end', function() {
                    console.log( 'connection ended' );
                });
        } );

    or using Promise (since 0.0.7):

    var herokuRun = require( 'herokuRun' ),
        runner = herokuRun( 'token', 'my-app-name' );
     
    runner.run( 'pwd && ls' )
        .then( function( logger ) {
     
            return new Promise( function( resolve, reject ) {
                logger
                    .on( 'connected', function( auth ) {
                        console.log( 'connected' );
                        console.log( (auth) ? 'authorized' : 'unauthorized' );
                    })
                    .on( 'data', function( data ) {
                         process.stdout.write( data.toString() );
                    })
                    .on( 'end', function() {
                        console.log( 'connection ended' );
                        resolve();
                    });
            } );
            
        } )
        .then( function() {
            // do something more...
        } )
        .catch( function( err ) ) {
            console.log( err );
        });

    Run bash and interact with dyno (demo/bash.js):

    var herokuRun = require( 'herokuRun' ),
        runner = herokuRun( 'token', 'my-app-name' );
     
    runner.run( 'bash', function( err, logger ) {
     
            if ( err ) {
             console.log( err );
             return;
            }
     
            logger
                .on( 'connected', function( auth ) {
                    console.log( 'connected' );
                    console.log( (auth) ? 'authorized' : 'unauthorized' );
                    process.stdin.on('data', function(chunk) {
                        logger.send(chunk);
                    });
     
                })
                .on( 'data', function( data ) {
                    process.stdout.write( data.toString() );
                })
                .on( 'end', function() {
                    console.log( 'connection ended' );
                    process.stdin.end();
                });
        } );

    How to test

    Add heroku credentials to tests/conf/heroku.json for end-to-end test to pass.

    {
        "herokutoken": "placeholder_for_valid_heroku_token",
        "app": "placeholder_for_valid_heroku_app_name"
    }

    Run npm install && npm test.

    Keywords

    none

    Install

    npm i herokuRun

    DownloadsWeekly Downloads

    5

    Version

    0.0.8

    License

    MIT

    Last publish

    Collaborators

    • amarczuk