Remote terminal with Total.js + Node PTY + xTerm
A simple tutorial how to create a remove terminal with help of Total.js Platform and modules Node PTY + xTerm.

- only 3 kB source-code
- Download example
Node.js dependencies:
node-ptytotaljs
Client-side dependencies:
xtermxterm-attach

Server-Side implementation
const Pty = require('node-pty');
exports.install = function() {
// Route to views/index
ROUTE('/');
// WebSocket route
WEBSOCKET('/', socket, ['raw']);
};
function socket() {
var self = this;
self.encodedecode = false;
self.autodestroy();
self.on('open', function(client) {
// Each client will have own terminal
client.tty = Pty.spawn('/bin/bash', [], { name: 'xterm-color', cols: 80, rows: 24, cwd: process.env.PWD, env: process.env });
client.tty.on('exit', function(code, signal) {
// What now?
client.tty = null;
client.close();
});
client.tty.on('data', function(data) {
client.send(data);
});
});
self.on('close', function(client) {
if (client.tty) {
client.tty.kill(9);
client.tty = null;
}
});
self.on('message', function(client, msg) {
client.tty && client.tty.write(msg);
});
}Client-Side implementation
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Remote terminal</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.14.5/xterm.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.14.5/xterm.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.14.5/addons/attach/attach.js"></script>
</head>
<body>
<div id="terminal"></div>
<script>
var term = new Terminal({ cols: 80, rows: 24 });
term.open(document.getElementById('terminal'));
var ws = new WebSocket(location.protocol.replace('http', 'ws') + '//' + location.hostname + (location.port ? (':' + location.port) : '') + '/');
ws.onopen = function() {
new attach.attach(term, ws);
};
ws.onerror = function(e) {
console.log(e);
};
</script>
</body>
</html>Keep reading
Using AI for Traffic Analysis and Smart Parking Monitoring
Discover how AI, NVIDIA Jetson AGX, and Total.js IoT transform camera data into traffic insights and automated parking occupancy monitoring.
Total.js Platform and NVIDIA DeepStream: Automated AI Video Anonymization
Discover how we combined Total.js Platform, Total.js Flow, and NVIDIA DeepStream to build a scalable, GPU-accelerated video anonymization system for a major enterprise customer. Explore how we process large volumes of video recordings, automate workflows across multiple locations, and manage AI-powered anonymization through a centralized interface.
October report 2026
A quick overview of all changes and news from the entire Total.js Platform. Read more about our work.
Node.js Security Vulnerabilities
Recent Node.js security updates have addressed serious vulnerabilities, including an issue in Brotli decompression. The news is particularly interesting because AI-assisted security research helped uncover a flaw in technology used by applications around the world.
September report 2026
A quick overview of all changes and news from the entire Total.js Platform. Read more about our work.
August report 2026
A quick overview of all changes and news from the entire Total.js Platform. Read more about our work.
How to write better Total.js Applications using AI?
Learn how to make AI coding agents write better, more native Total.js applications!
July report 2026
A quick overview of all changes and news from the entire Total.js Platform. Read more about our work.
Total.js AIModel: a practical foundation for AI-powered workflows
How Total.js helps developers integrate AI models into real applications with routing, actions, streaming, tools, validation, and business logic in one coherent stack.
June report 2026
A quick overview of all changes and news from the entire Total.js Platform. Read more about our work.