Issue commands from the terminal with node.js


A utility to use with the input from terminal (process.stdin) while the application is running and emit events to handle internal server commands

I found it very useful while developing for example a chat application, using the event emitall and passing the message to all the connected sockets. In order to test, or in a production environment to make a global announcement.


With npm

$ npm install consolr


After you run your node application this leaves you with a prompt, just type what you need and press enter. Simple example, running this code will allow you to exit the application typing exit.

var consolr = require('consolr');
consolr.on('command', function(command){
    console.log("User have been input some command handle it as you need");
    if(command == 'exit'){
        console.log('Closing the app');

Custom events, to create custom events just type :yourcustomevent and then some text if you need it. eg.

:exit Closing the app
var consolr = require('consolr');
consolr.on('exit', function(command){

The second example does the same as the first one

Now accepts JSON code, for example (It also works on the predefined event)

:someevent {message: 'Testing JSON', key:'value'}
var consolr = require('consolr');
consolr.on('someevent', function(data){

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s