The JavaScript blog.


node command-line servers libraries

Add a CLI to Node Apps with Vantage

Posted on .

Vantage (GitHub: dthree/vantage, License: MIT, npm: vantage) by David Caccavella is a very nicely packaged module for adding command-line interfaces to your Node applications. It provides two components: a server, and a command-line tool that you use to connect to your live app. Rather than connecting to a TCP port with something like telnet, you actually type vantage in the command-line.

To hook it up to your application, you'll need to add a Vantage server. First, install Vantage to your project (npm install --save vantage), then instantiate a Vantage object and hook up the functionality that you want:

var Vantage = require('vantage');  
var server = new Vantage();

  .description('Outputs "bar".')
  .action(function(args, cb) {
    // Do anything: check the database, run migrations, show useful stats


I'd put this in a separate file to your main Express/Koa/Hapi/etc. app server, then add Vantage actions for the desired functionality. You could add things like database queries, or heartbeat/usage info, and so on.

Once you've added Vantage to your web app, if you install it globally you'll be able to just type vantage ip:port to connect to your server. Typing help will display the built-in commands and any actions that you've added. You should see something like this for the previous example:

webapp~$ help


    help [command]    Provides help for a given command.
    exit [options]    Exists instance of Vantage.
    vantage [server]  Connects to another application running vantage.
    foo               Outputs "bar".

In addition to basic commands and subcommands, Vantage uses inquirer for prompts. Inquirer's prompts are quite powerful: they're ideal for things like yes/no questions and checkboxes. You could use it to force a "yes/no" prompt before a irreversible operation.

Vantage has a few other nice features that'll make your backdoor feel more professional: you can add a banner when people sign in (perhaps with legal warnings, or help), it supports a "firewall" for limiting access, and the documentation has details for using Vantage with Express, Koa, and TLS/SSL.

On the subject of backdoors: Vantage doesn't currently support authentication. It may be possible to use it as a limited informational interface to your server, but I'd strongly recommend binding to internal interfaces only. That means you'd have to ssh to a server, and then run vantage remotely. If that's not possible or convenient, then at least set up TLS/SSL. The current idea for authentication is to support it through middleware -- it already supports middleware so actions can be made reusable, so it seems like a sensible approach.

Authentication issues aside, it definitely seems like something worth using for development servers: I know many people who would love to see their Node web apps get the kind of consoles that popular web frameworks offer (Django's manage.py shell and Rails' console are two that spring to mind). Check it out, but try local/development mode first!


apps realtime servers node

A Server for Realtime Apps: deepstream.io

Posted on .


Wolfram Hempel sent in an open source server called deepstream.io (GitHub: hoxton-one/deepstream.io, License: MIT, npm: deepstream.io). Deepstream is a Node server that allows clients to sync data, whether they're browsers or mobile applications. It has a caching layer, and supports event-based messaging and RPC.

If you install deepstream.io with npm, you can create a simple server like this:

var DeepstreamServer = require( 'deepstream.io' );  
var server = new DeepstreamServer();

server.set('host', 'localhost');  
server.set('port', 6020);


Then in the browser you can connect with var ds = deepstream('localhost:6020').login(). The ds object can be used to fetch and set data. The tutorial shows how to do this with a simple HTML form:

var record = ds.record.getRecord('someUser');  
var input = document.querySelector('input');

input.onkeyup = function() {  
  record.set('firstname', input.value ;

record.subscribe('firstname', function(value) {  
  input.value = value;

The RPC calls allow functions to be bound to function names. One nice property of RPC in deepstream is if multiple clients are able to provide the same RPC, it will distribute requests evently between them.

The project is still new, but there are a good amount of tutorials already, including React and Angular examples.


meteor books plugins databases servers apps mysql sponsored-content jquery

Your First Meteor Application, OData Server, ItemSlide.js

Posted on .

Your First Meteor Application

Your First Meteor Application

David Turnbull's Your First Meteor Application is a highly focused, beginner-friendly introduction to Meteor. David updates the book regularly when Meteor changes, so it's worth checking back every so often to look for new content.

You can read the book online or download the PDF for free. If you prefer video, there are also screencasts for $39.

OData Server

The OData Server (GitHub: gizur/odataserver, License: MIT, npm: odataserver) by Jonas Colmsjö is an OData server that's backed by MySQL. It's easy to drop into an Express project, and it's designed to work as a quick "mobile backend as a service" type of app.

It has a simple HTTP API, and Jonas has included usage examples for curl that show you how to create users, databases, and insert data. It actually does things like MySQL database and schema creation, so it requires a MySQL administrator account to work correctly.

If you're interested in this and want to quickly try it out, the advanced usage guide has instructions for deploying it to Docker.


ItemSlide.js (GitHub: itemslide/itemslide.github.io, License: MIT, npm: itemslide) by Nir Lichtman is a touch-friendly carousel.

With jQuery you can set it up like this:

var carousel = $('ul');  
carousel.itemslide({ swipe_out: true });  

And it has events for responding to user interaction:

carousel.on('pan', function(e) {});  
carousel.on('changeActiveIndex', function(e) {});  
carousel.on('changePos', function(e) {  
  console.log('new pos:', carousel.getCurrentPos());
carousel.on('swipeout', function(event) {  
  console.log('swiped out slide:', event.slide);

You don't have to use it with jQuery, but if you do you'll get things like mousewheel support.


events node servers pubsub


Posted on .


Autobahn|JS (GitHub: tavendo / AutobahnJS, License: MIT, npm: autobahn) is an implementation of a protocol that supports RPC and PubSub that runs over WebSocket, with fallbacks for older browsers.

The PubSub model supports topics, and uses a promise-based API:

// Subscribe to a topic
session.subscribe('com.myapp.topic1', onEvent).then(  
  function(subscription) {
    console.log('Subscribed:', subscription);
    currentSubscription = subscription;

  function(error) {
    console.error('Error:', error);

The support for RPC is based on a router, where routes are represented as strings. Registering a remote procedure also uses a promise:

// Define the remote procedure
function utcnow() {  
  var now = new Date();
  return now.toISOString();

// Register the remote procedure with the router
session.register('com.timeservice.now', utcnow).then(  
  function(registration) {
    console.log('Procedure registered:', registration.id);
  function(error) {
    console.error('Registration failed:', error);

You can call this remote procedure with session.call('com.timeservice.now'), which again returns a promise.

To use Autobahn, you also need an application router. The documentation mentions Crossbar.io. This allows you to create distributed server applications, so you could route between backends running on different platforms. Authorization is supported, so you can limit access to server-side resources.

The project is based on an open protocol called WAMP (Web Application Messaging Protocol). Other WAMP implementations include Autobahn|Android and wampy.js.


node email modules npm servers

Receiving Emails with Node

Posted on .

One of the things I like to evangelise about Node is the fact it's good for creating any network servers, not just web stuff. Florent Galland sent in Mailin (GitHub: Flolagale / mailin, License: MIT, npm: mailin), which allows your web apps to receive inbound emails. What's cool about Mailin is it runs as an SMTP server, so rather than having to configure a mail server you can just use Mailin by itself.

Mailin's homepage has a cool demo that allows you to send it an email and see it appear on the page. This works using Mailin's webhook.


You can configure the webhook when the server is started:

mailin --webhook http://example.com/incoming_emails  

The documentation explains how to install it with authbind for safe binding to port 25, otherwise sudo or a root user would be required.

The documentation also mentions optional spam detection support.

Mailin is built with the simplesmtp module. This provides a Node API for building SMTP servers. It has an API that should be familiar to anyone who has written HTTP code with Node:

simplesmtp.createSimpleServer({ SMTPBanner: 'My Server' }, function(req) {  

simplesmtp even supports connection pools, and TLS. I love the idea of using Node for servers that I can customise, but I'm not a security expert so I don't know what the implications of using these modules in production might be. Maybe it's time I read Node Security!