Vantage gives you a new perspective into your live node application not previously available.
An extension of Vorpal, Vantage turns your live Node app into a immersive CLI. Accessible remotely or locally, Vantage lets you build your own API for your application and import community extensions, introducing a new means of live diagnostics and activity for your dev and prod environments.
First-class CLI: tab completion, history, you name it.
Build your own API with the familiar syntax of commander.js.
SSH-like client / server setup for remote access to your live Node app.
Production-ready, with authentication middleware and a basic firewall.
Built-in REPL.
Unlike any other REPL or CLI module, Vantage allows you to remotely connect to your live app and access the CLI transparently, exactly as you would in an SSH session. Vantage can connect through an unlimited number of live Node instances across multiple machines, piping commands and information to and from your local terminal.
// Create a new instance of vantage.
var vantage = require("vantage")();
// Add the command "foo", which logs "bar".
vantage
.command("foo")
.description("Outputs 'bar'.")
.action(function(args, callback) {
this.log("bar");
callback();
});
// Name your prompt delimiter
// "websvr~
quot;, listen on port 80
// and show the Vantage prompt.
vantage
.delimiter("websvr~quot;)
.listen(80)
.show();
Run server.js. You Node app has become a CLI.
$ node server.js
websvr~$
Open another terminal. Because Vantage is listening on port 80, you can remotely connect to it:
$ vantage 80
$ Connecting to 127.0.0.1:80 using http...
websvr~$
Try out your "foo" command.
websvr~$ foo
bar
websvr~$
Now type "help" to see Vantage's built in commands in addition to "foo":
websvr~$ help
Commands
help [command] Provides help for a given command.
exit [options] Exits instance of Vantage.
use <module> Installs a vantage extension in realtime.
vantage [server] Connects to another application running vantage.
foo Outputs "bar".
websvr~$
That's the basic idea. Once you get the hang of it, read on to learn some of the fancier things Vantage can do.
API
Vantage is an extension of Vorpal, and so inherits all of its properties and methods. For all command creation and CLI syntax, refer to Vorpal's API.
.listen(app, [options or callback], [callback])
Starts Vantage as a server.
Vantage as a standalone web server
If you just want it to listen on a port independent of your web application, simply pass in the port and Vantage will spawn a new HTTP server. Every time a client connects to Vantage, the connection callback will be thrown and include the socket.io connection object.
var vantage = new Vantage();
vantage.listen(80, function(socket){
this.log("Accepted a connection.")
});
Vantage with an existing web server
If you want Vantage to listen on the same port as your web application, you can use Vantage's listen function in place of your existing web server's listen function.
This is useful when running clustered instances of your server, such as behind a reverse proxy, where every instance has a separate port that can only be accessed internally. In this way, you can hop into any running instance without having to remember a separate set of ports.
With Koa.js
var koa = require('koa');
var Vantage = require('vantage');
var vantage = new Vantage();
var app = koa();
vantage.listen(app, 80);
With Express.js
var express = require('express');
var Vantage = require('vantage');
var vantage = new Vantage();
var app = express();
vantage.listen(app, 80);
With Hapi.js
var Hapi = require('hapi');
var Vantage = require('vantage');
var vantage = new Vantage();
var server = new Hapi.Server();
vantage.listen(server, 80);
server.start();
With SSL / advanced options
You can pass detailed options to your web server with the second argument in place of the port. These options are the same options you would pass into your web server, with a few exceptions:
options.port: Tells vantage what port to listen on.
options.ssl: A boolean that tells Vantage whether to spawn an HTTP or HTTPs server.
options.logActivity: When true, a TTY acting as a Vantage server that receives a connection will log when clients log in and out of the server. Defaults to false.
Sets a banner for display when logging into a given Vantage server.
var banner =
"######################################################################" +
"# Welcome to joescrabshack.com #" +
"# #" +
"# All connections are monitored and recorded #" +
"# Disconnect IMMEDIATELY if you are not an authorized user #" +
"######################################################################";
vantage
.delimiter('appsvr:3000~