Total.js Framework v5
Total.js v5 is a full-stack, server-side MVC framework for Node.js, written entirely in pure JavaScript. It is designed to build web, desktop, service, and IoT applications, providing a comprehensive, dependency-free ecosystem (excluding specific database connectors). The current stable version on npm is 0.0.15 (as of late 2025), representing the fifth major iteration of the Total.js platform. Initially released in beta around November 2023, it was declared 'almost stable' by January 2024. Total.js differentiates itself by embracing a 'pure JavaScript' philosophy, explicitly discouraging TypeScript usage, and integrating core functionalities like a web server, robust routing, an embedded NoSQL database (TextDB), WebSockets, and cron job management directly into the framework. It targets Node.js version 19 or higher, aiming for high performance and minimal external tooling.
Common errors
-
ReferenceError: ROUTE is not defined
cause The Total.js framework was not properly initialized via `require('total5')` at the beginning of the script, or the script is not being run directly by Node.js.fixEnsure `require('total5');` is at the top of your main application file (e.g., `index.js`) before any `ROUTE` or other global Total.js functions are called. Then run with `node index.js`. -
TypeError: $.req.body.someProperty is not a function/property
cause In Total.js v5, direct `request` and `response` objects (`$.req`, `$.res`) have been removed from the controller instance (`$`). You should access data and methods directly on `$` or its helper properties.fixRefactor your code to use the new controller API. For example, use `$.body` for POST/PUT body data, `$.query` for query parameters, or specific helper methods provided by the `$` instance. -
Error: Total.js v5 requires Node.js version >= 19
cause The Node.js runtime version being used is older than the minimum requirement for Total.js v5.fixUpdate your Node.js environment to version 19 or later. You can use tools like NVM (Node Version Manager) to manage multiple Node.js versions.
Warnings
- breaking Total.js v5 introduces significant changes to routing. Direct access to `request` and `response` instances (`$.req`, `$.res`) is removed. All request/response handling is now abstracted through the `controller` instance (alias `$`).
- breaking The `SESSION()` method for internal session management has been removed in Total.js v5. Developers should now use the `AUTH()` method, which includes predefined session functionality, or implement custom session handling.
- breaking The `PREF` global for persistent preferences has been removed. Its functionality is replaced by the `MEMORIZE(name)` method.
- breaking For data schemas, `schema.define()` is no longer supported in Total.js v5. Schema actions should be defined directly using `schema.action()`.
- gotcha Total.js v5 has a strong philosophy of pure JavaScript development and explicitly states that users wanting to use TypeScript will be disappointed. The framework is optimized for direct JavaScript without transpilation.
- gotcha Total.js v5 requires Node.js version 19 or higher. Running on older Node.js versions may lead to unexpected errors or stability issues.
- gotcha The documentation for Total.js v5 is still incomplete, and developers may need to consult source code, community channels, or older documentation (v3/v4) for certain features or patterns.
Install
-
npm install total5 -
yarn add total5 -
pnpm add total5
Imports
- total5
import total5 from 'total5';
require('total5'); - ROUTE
import { ROUTE } from 'total5';ROUTE('GET /', function($) { /* ... */ }); - Total.http
import { http } from 'total5';Total.http({ load: 'none' }); - NEWSCHEMA
import { NEWSCHEMA } from 'total5';NEWSCHEMA('Users', function(schema) { /* ... */ });
Quickstart
const framework = require('total5');
// Register a simple GET route
ROUTE('GET /', function($) {
// $ represents the controller instance
$.json({ message: 'Hello world from Total.js v5!' });
});
// Register a WebSocket route
ROUTE('SOCKET /chat/', function($) {
$.on('open', function(client) {
console.log('Client connected:', client.id);
client.send({ message: 'Welcome to the chat!' });
});
$.on('message', function(client, message) {
console.log(`Message from ${client.id}:`, message);
// Broadcast the message to all connected clients
$.send({ sender: client.id, text: message.text || message });
});
$.on('close', function(client) {
console.log('Client disconnected:', client.id);
});
});
// Launch the web server on port 8000
Total.http({
port: process.env.PORT ?? 8000,
load: 'none' // 'none' for minimal setup, 'release' for production
});
console.log(`Total.js v5 server running at http://127.0.0.1:${process.env.PORT ?? 8000}/`);
console.log(`WebSocket server running at ws://127.0.0.1:${process.env.PORT ?? 8000}/chat/`);