• No products in the cart.


Retrieve Password
Back to login/register

Server Automation for NodeJS over SSH with Nodemiral by Ray Mahangoe

Nodemiral is like Ansible, an automation tool based on Javascript/NodeJS. While Ansible has been around for a while, Nodemiral is still young (though Javascript has been in the loop for a while). Why do I use Nodemiral? Well, I’ve been using Ansible for a while and I like the way Ansible works, like access with ssh, playbooks and run script on a server, etc., and there is no need to install a client on every server.

The point is, I like NodeJS and where ever it’s possible, I make scripts to do some automation in NodeJS and when I saw this package “Nodemiral” for NodeJS, I started playing with it.

In my opinion, Nodemiral Is still a work in progress and not completely ready for production uses, like Ansible or Puppet are, although it’s good to play and experiment with. For some simple auto- mation stuff for small/medium organizations that don’t have a complicated infrastructure, Nodemi- ral can do a good job.

Nodemiral is nice but I will not compare it yet with Ansible, Puppet or other automation tool for now.

If you still want to try and use it, test it pretty good before automating your server task with Node- miral, in this case go ahead and give Nodemiral a chance.

In my case, I’m running a Nodemiral test environment with 10 VMs, mixed with Linux (Debian, CentoS) and FreeBSD 10 & 11. It works fast and I feel at home with Javascript/Nodejs. ;-).

I think there is a good chance that this automation tool based on NodeJS will get up against the bigger tools in the future. Till that time I’ll keep playing and testing automation tools based on NodeJS.


• Support connecting to any Unix remote server
• Authenticate with password (using sshpass) or with a pem file
• Can work with multiple servers at once
• Supports, copy, execute and executeScript at core methods Familiar NodeJS API Requirements and


  • Some basic knowledge with Javascript/NodeJS.
  • Nodemiral is a package for NodeJS and the requirements are the same as for Javascript.
  • You need to installed nodejs on your main server/workstation from where you want to control/ manage all your servers. There are plenty of tutorials on how to install Nodejs on the internet for Unix / Linux / OSX and Windows.Installation:

    Create a script for example nodemiral.js and past the code into it and save it.
    This script will: login to a linux/unix server ‘hostname” and will execute the command “uname -a” Example:

$npm install


Create a script for example nodemiral.js and past the code into it and save it. This script will: login to a linux/unix server ‘hostname” and will execute the command “uname -a”.


 var nodemiral = require(‘nodemiral’);
var session = nodemiral.session('hostname', {username: 'root', pass-
word: 'password'});
session.execute('uname -a', function(err, code, logs) {


hostname = hostname or ip addess
auth = object containing following fields: `username` and (`password`
or `pem`) err = err if exists
code = status code of the ssh process
logs = {stdout: 'stdout logs', stderr: 'stderr logs'}

Run the script called nodemiral.js

 $node nodemiral.js

Other examples how to use Nodemiral

Session: Create a session to a remote server. You can invoke the following methods after you cre- ated a session example:

var session = nodemiral.session(hostname, auth, options);
hostname = hostname or ip addess
auth = object containing following fields: `username` and (`password`
or `pem`) options = object of options described below.
  • –  ejs = ejs options with ejs fields
  • –  ssh = object whose key and value will be passed as -o key: value to any ssh session. For example: { ‘StrictHostKeyChecking’: ‘no’, ‘UserKnownHostsFile’: ‘/dev/null’ }

Session.execute: execute given shell command on the remote server:

var session = session.execute(shellCommand, options, callback);
shellCommand = shellCommand options = {onStdout, onStderr}
callback = callback containing following parameter

Session.executescript: execute a local shell script in the remote server. You can template shell script with https://github.com/tj/ejs

var session = session.executeScript(localScriptFile, options, callback);
localScriptFile = localScriptFile
options.vars = variables to the template if uses ejs in the script
callback = callback containing following parameters

Session-copy: copy a file from local machine to the remote machine. Supports binary files too. Support EJS templating with non-binary files.

var session = session.copy(localFile, remoteFileLocation, options,
localFile = localFile
remoteFileLocation = remoteFileLocation options.vars = templateVars
options.progressBar = show progress bar
callback = callback containing following parameters

About the Author:

My name is Ray I live in Amster- dam the Netherlands.
 I started my IT future back in 1992 with playing around with a Atari 1024ST and MSDOS emulator.
Its was so fascination for me that I started to do more research and selfstudy en got Novell NetWare administrator Certification in 1994.
In 2012 I started to play with DragonFly, OpenBSD and FreeBSD. I felt directly home with FreeBSD and I started working for the European

Aerospace in The Netherlands and they uses FreeBSD as main server for Storage, Web, PHP, Mysql, Ldap authentication, Firewall etc and CentOS for Matlab cluster.

In 2014 I went to an other company UPC “bought by AMC Network” and I implemented FreeBSD & ZFS and GlusterFS as one big storage pool of 18PB of capacity.
These days my main focus and interest is, FreeBSD, ZFS, GlusterFS, NodeJS and Openstack.

As hobby I do make Electronical Music and I also give Dance Workshop and Contact Improvisa- tion trainings. 😉

Article comes from BSD Mag VOL. 10 NO. 05 (81)

Leave a Reply

Be the First to Comment!

Notify of
© HAKIN9 MEDIA SP. Z O.O. SP. K. 2013