---
title: Command line (total4)
project: Total.js V4
version: 0.0.99
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/guides/command-line/
updated: 2026-11-16T15:41:15.818Z
---

# Command line (total4)

> The total4 command-line tool: creating projects, serving a folder, bundles, minifying and localization resources.

The `total4` package installs a small command-line tool, also called `total4`. It lists the official project templates, serves a folder over HTTP, makes and extracts bundles and packages, minifies files and works with localization resources.

## Installation

The tool is the `bin` entry of the `total4` package. Install the package globally to get the command everywhere:

```bash
npm install -g total4
total4 help
```

Every run prints a header box with the Total.js version first, then the result of the command. Without a command the tool prints `Use "total4 help" to list all commands.`; an unknown command prints an error with the same advice.

## Writing commands

A command is the first argument. Each command accepts three spellings: `bundle`, `-bundle` and `--bundle` are the same (the tool removes one leading dash from `--name`). Some commands also have a short alias:

| Command | Aliases |
| --- | --- |
| `help` | `h`, `-h`, `--help` |
| `version` | `-v`, `--version` |
| `translate` | `-t` |
| `translatecsv` | `-c` |
| `translate4` | `-4` |
| `minify` | `-compress`, `-compile` (and their `--` forms) |
| `edit` | `-e` |

Paths are resolved from the current directory, and every output file is written there or next to the input file.

## Serving a folder

A number as the first argument starts a static web server for the current directory:

```bash
cd ~/www/landing
total4 8000
```

The server runs in debug mode on all interfaces (`0.0.0.0`) and the given port. A request for a directory returns its `index.html`; when there is none, the server renders a simple directory listing with links to subdirectories and files and their sizes. Files are sent as they are: HTML, scripts and styles are not compiled, and `.less` files are served as `text/less`. The temporary files of the server go to the temporary directory of the system, so the folder stays clean. Stop the server with `Ctrl+C`.

## Templates

`total4 templates` downloads the list of official project templates and prints the name and description of each one:

```bash
total4 templates
```

## Bundles and packages

A bundle is one `.bundle` file with a whole application or a part of it. The framework extracts bundles from `/bundles/` when the application starts; [Application structure](../../guides/application-structure/) explains how bundles are merged. Make a bundle from the current directory:

```bash
cd ~/projects/eshop
total4 bundle eshop.bundle
```

The tool prints the directory, the file name and then the number of files and the size. The default name is `app.bundle`; give your own name with the `.bundle` extension. These paths are never included: `/bundle.json`, `/debug.js`, `/release.js`, `/index.js` (and their `.json` and `.pid` files), `/package.json`, `/readme.md`, `/license.txt`, `/bundles/`, `/tmp/`, `/.src/`, `/.git/` and the bundle file itself.

`total4 package <filename>` makes a `.package` file in the same way (default `noname.package`; give your own name with the `.package` extension). Its list of excluded paths is shorter: `/bundle.json`, `/debug.js`, `/release.js`, `/debug.pid`, `/package.json`, `/readme.md`, `/license.txt`, `/bundles/`, `/tmp/` and `/.git/`. Copy the result to `/packages/` of an application.

`total4 extract <filename>` writes all files of a bundle or a package into the current directory:

```bash
mkdir restored && cd restored
total4 extract ../eshop.bundle
```

Existing files with the same path are overwritten, so extract into an empty directory.

## Minifying files

`total4 minify <filename>` minifies one `.js`, `.css` or `.html` file with the framework's own minifiers and writes `<name>.min.<extension>` next to it:

```bash
total4 minify public/js/app.js
# Minified: .../public/js/app.min.js
```

The file name is always the last argument. Files with other extensions are not written.

## Localization

The translation commands produce resource files for the framework's localization, see [Localization](../../guides/localization/). A resource line is `key : text`; the keys of texts from views are `T` followed by a hash of the text in base 36.

`total4 translate`, run in the root of the application, reads every `.html` and `.js` file (and every file with `sitemap` in its path) of the current directory and all its subdirectories. It collects:

- every `@(text)` marker; texts that start with `#` followed by a non-space character are skipped,
- in `.js` files, error keys used as `$.invalid('key')`, `.error('key')` and `.err('key')`; their key is the text itself.

The result is `translate.resource` in the current directory, grouped by a `// filename` comment:

```bash
cd ~/projects/eshop
total4 translate
# Translation has been created successfully (128 texts)
```

Copy it to `/resources/` under the name of a language, for example `sk.resource`, and translate the texts.

`total4 translate "Text"` prints the resource line for one text, so you can add it to a resource by hand. When the argument is an existing file, `total4 translate <filename>` creates `translate.resource` with one key for each non-empty line of that file.

## CSV for translators

`total4 translatecsv` reads the same files as `translate` (only `@(text)` markers) and writes `translate.csv` with the columns `Hash;Text;Translation`.

## Maintaining resources

| Command | Output | What it does |
| --- | --- | --- |
| `diff <source> <target>` | `<target>-diff.txt` | Lists keys of `source` missing in `target` ("Add") and keys of `target` missing in `source` ("Remove") |
| `merge <source> <target>` | `<target>-merged.txt` | Copies `target` and replaces each text with the text from `source` when `source` has the key |
| `clean <source>` | `<source>-cleaned.txt` | Aligns all keys to one column and keeps comments and empty lines |
| `translate4 <source>` | `<source>` with `-new` before the first dot | Converts old numeric keys (`T123`, `T-123`) to the base-36 keys of Total.js 4 |

The output file names drop the `.resource` extension: `total4 diff default.resource sk.resource` writes `sk-diff.txt`. `translate4` inserts `-new` before the first dot of the argument: `total4 translate4 sk.resource` writes `sk-new.resource`.

A typical update of a translation after new texts appear in the views:

```bash
total4 translate
total4 diff translate.resource resources/sk.resource
# add the keys from resources/sk-diff.txt and translate them
total4 clean resources/sk.resource
```

## Total.js Code Editor

`total4 edit <url>` connects the current directory to a project in the Total.js Code Editor over WebSocket. The URL is the address of the project, for example `https://code.example.com/?id=myproject`; `http` is changed to `ws` automatically. The editor can then browse, read, create, save, rename, upload and remove the files of the directory and read its logs. The tool prints the directory and a welcome line with the name of the project, reconnects every 10 seconds, prints `404 project not found` while the project does not exist and stops with `409 project is already open` when another client has the project open.
