---
title: Installazione e prima app
project: Total.js V4
version: 0.0.99
section: guides
language: it
license: MIT
url: https://totaljs.es/docs/it/total-js-v4/0-0-99/guides/installation/
updated: 2026-11-16T15:41:00.817Z
---

# Installazione e prima app

> Installa Total.js 4, scrivi lo script di avvio e rispondi alle tue prime richieste.

## Requisiti

Node.js. Total.js 4 non ha dipendenze e non richiede una versione specifica di Node.js; usa una versione LTS attuale.

## Installazione

```bash
mkdir myapp
cd myapp
npm init -y
npm install total4
```

## Lo script di avvio

Crea `index.js`. È lo script di avvio ufficiale di Total.js 4, ridotto a ciò che ti serve ora:

```js
const options = {};

// options.ip = '127.0.0.1';
// options.port = parseInt(process.argv[2]);
// options.config = { name: 'My app' };

var type = process.argv.indexOf('--release', 1) !== -1 ? 'release' : 'debug';
require('total4/' + type)(options);
```

Eseguilo:

```bash
node index.js
```

L'app è in ascolto sulla porta **8000**. In modalità **debug** si riavvia da sola quando modifichi un file. In produzione avviala con `node index.js --release`.

## Le tue prime route

Crea `controllers/default.js`:

```js
exports.install = function() {
	ROUTE('GET /', home);
	ROUTE('GET /hello/{name}/', hello);
};

function home() {
	this.plain('Hello world');
}

function hello(name) {
	this.json({ hello: name });
}
```

Apri `http://127.0.0.1:8000/` e `http://127.0.0.1:8000/hello/Peter/`. Ogni azione viene eseguita con il controller come `this`, e le parti dinamiche dell'URL arrivano come argomenti.

## Opzioni dello script di avvio

| Opzione | Cosa fa |
| --- | --- |
| `ip`, `port` | Indirizzo e porta del server (porta predefinita `8000`) |
| `unixsocket` | Ascolta su un socket Unix invece che su una porta |
| `config` | Valori che sovrascrivono il file `config` |
| `sleep` | Attende prima di avviarsi, in millisecondi |
| `inspector` | Apre l'inspector di Node.js su una porta |
| `watch` | Cartelle aggiuntive che riavviano l'app in modalità debug |
| `https` | `key` e `cert` per servire HTTPS direttamente |
| `cluster`, `cluster_limit` | Esegue più processi (`'auto'` li scala) |
| `servicemode` | Si avvia senza il server web (`--servicemode`) |

## Prossimi passi

Leggi [Routing](../routing/) per imparare tutta la sintassi di `ROUTE()`.
