Total.js Framework
Total.js is a full-stack, open-source Node.js framework designed for creating web applications, REST services, real-time applications, and IoT solutions. Written in pure JavaScript without external dependencies (beyond optional database connectors or specific modules), it aims for high performance and clean architecture, similar to MVC frameworks like Laravel or Django. The framework emphasizes backward compatibility, with version 3 (3.4.13 being a recent patch) receiving frequent updates and bug fixes. It includes a built-in web server, static file handling, powerful routing, an embedded NoSQL database (TextDB), image processing via GraphicsMagick or ImageMagick, WebSockets, a custom view engine, and a schema system for data validation and workflows. Total.js differentiates itself by providing a comprehensive, independent platform often used with its ecosystem of tools like Total.js Code Editor and CMS. While Total.js v3 is actively maintained, the project has transitioned to newer major versions (v4, `total4` on npm, and v5, `total5` on npm), which introduce significant architectural changes and target newer Node.js versions, although v3 continues to be supported for existing projects.
Common errors
-
Error: Cannot find module 'total.js'
cause The `total.js` package is not installed in the project's `node_modules` or globally, or Node.js cannot resolve its path.fixEnsure `total.js` is installed locally in your project: `npm install total.js` or globally if using its CLI tools: `npm install -g total.js`. Also, verify your `index.js` or `app.js` file is in the correct location or the `require` path is accurate. -
TypeError: ROUTE is not a function
cause The Total.js framework was not properly initialized before `ROUTE` (or other globals like `F`, `CONTROLLER`) was called, meaning these global functions are not yet exposed.fixEnsure `require('total.js')();` or `require('total.js').http('debug');` is called at the very beginning of your main application entry file (`app.js` or `index.js`), before any routes or controllers are defined. The framework needs to bootstrap itself to expose its globals. -
Error: Image command 'convert' not found or not installed.
cause The underlying image processing library (GraphicsMagick or ImageMagick) required by Total.js's image handling features is not installed on the system path.fixInstall GraphicsMagick or ImageMagick on your operating system. For Debian/Ubuntu, use `sudo apt-get install graphicsmagick` or `sudo apt-get install imagemagick`. For other OS, refer to their respective package managers or installation guides.
Warnings
- breaking Total.js v4 and v5 are separate NPM packages (`total4` and `total5`) and are not directly backward compatible with Total.js v3. Upgrading requires migration, although some functionality is maintained.
- gotcha Total.js heavily relies on global functions and objects (e.g., `ROUTE`, `CONTROLLER`, `F`, `SCHEMA`, `U`) once the framework is initialized. This differs significantly from module-based Node.js development and can lead to potential global namespace pollution or confusion for developers accustomed to explicit ES Modules imports.
- gotcha The framework expects a specific directory structure (e.g., `controllers`, `views`, `schemas`, `public`) for automatic loading of application components. Deviating from this structure without explicit configuration can lead to modules not being found or processed.
- gotcha Image processing features rely on external system dependencies like GraphicsMagick or ImageMagick, which are not installed via NPM. These must be installed manually on the server where the Total.js application runs.
- deprecated Total.js v3 is a CommonJS-first framework. While Node.js increasingly supports ES Modules (ESM), Total.js v3's internal architecture and public API are designed around CommonJS `require()` and globals. Direct `import` statements for core Total.js functionalities will not work without transpilation or specific Node.js configuration for hybrid modules, which is generally not the intended usage for v3.
Install
-
npm install total.js -
yarn add total.js -
pnpm add total.js
Imports
- total.js
import { F } from 'total.js';const F = require('total.js'); // or just: require('total.js'); - ROUTE
import { ROUTE } from 'total.js'; ROUTE('GET /', ...);ROUTE('GET /', function() { /* ... */ }); - F
import { F } from 'total.js';F.on('ready', () => console.log('Total.js is ready!'));
Quickstart
const framework = require('total.js');
// Start the framework in debug mode
// In a typical Total.js setup, this would be in your main application file (e.g., app.js or index.js)
// and the framework automatically scans for controllers, views, etc.
// For a simple standalone script, you can explicitly call .http() or .https().
// To run a full Total.js application, you'd usually have a directory structure
// with 'controllers', 'views', 'schemas', etc., and then start it with:
// require('total.js').http('debug');
// For this quickstart, we'll demonstrate a simple route definition directly:
// Define a simple GET route
ROUTE('GET /', function() {
// 'this' inside a route handler refers to the Controller instance
this.plain('Hello from Total.js!');
});
ROUTE('GET /api/data', function() {
this.json({
message: 'This is some data from Total.js API',
timestamp: new Date()
});
});
// Listen on HTTP port 8000 (default for debug mode)
framework.http('debug', { port: 8000 });
console.log('Total.js application running in debug mode on http://127.0.0.1:8000');