Skip to content

Enabling colors in term.js

I am using term.js for emulating a terminal in the web browser via JavaScript and Node.js.

I have already setup the basic implementation and I can connect to both local as well as remote host (I use node ssh2 to connect to a remote host). Everything works as expected, except that it’s black and white (black background, white text).

I have the following code in the client which is as per the example in the repository. Should I add some extra configuration to enable colors?

var term = new Terminal({
  colors: Terminal.colors, // This alone doesnt seem to work
  cols: 80,
  rows: 24,
  useStyle: true,
  screenKeys: true,
  cursorBlink: true


Color works for me. Here’s my test setup on Ubuntu:

Install dependencies first: npm install express ssh2 term.js

Install the colortest package on the remote server (that you’re ssh’ing into): sudo apt-get install colortest -y


var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('')(server);

var term = require('term.js');
var ssh = require('ssh2');


app.use(express.static(__dirname + '/public'));

io.on('connection', function (socket) {
  var conn = new ssh();
  conn.on('ready', function() {
    socket.emit('data', 'n*** SSH CONNECTION ESTABLISHED ***n');
    conn.exec('env TERM=xterm-256color colortest-256', function(err, stream) {
      if (err)
        return socket.emit('data', 'n*** SSH EXEC ERROR: ' + err.message + ' ***n');
      stream.on('data', function(d) {
        socket.emit('data', d.toString('binary'));
      }).on('close', function() {
  }).on('close', function() {
    socket.emit('data', 'n*** SSH CONNECTION CLOSED ***n');
    host: '',
    port: 22,
    username: 'foo',
    password: 'barbaz',


    <script src="/"></script>
    <script src="/term.js"></script>
      window.addEventListener('load', function() {
        var socket = io.connect();
        socket.on('connect', function() {
          var term = new Terminal({
            cols: 250,
            rows: 100,
            convertEol: true,
            useStyle: true,
            cursorBlink: true,
            screenKeys: true

          term.on('data', function(data) {
            socket.emit('data', data);

          term.on('title', function(title) {
            document.title = title;


          socket.on('data', function(data) {

          socket.on('disconnect', function() {
      }, false);

Execute node server.js and then visit http://localhost:8000/client.htm in your browser. You should see something like this.