Skip to content

Chapter 37: Complete Feature List

This chapter catalogs all 44 features in Tina4 for Node.js, grouped by category. Use it as a reference when starting a project or auditing what you need.


1. Routing and HTTP

#FeatureClass / FunctionChapter
1HTTP RoutingRouter.get/post/put/delete/patch/all2
2Route Parametersreq.params.id, {id:int}, {slug}2
3Request & Responsereq.body, req.query, res.json, res.render, res.status3
4MiddlewareRoute-level string middleware, "auth", "ResponseCache:300"10
5Static FilesServed from public/ automatically1
6CORSTINA4_CORS_ORIGIN, TINA4_CORS_HEADERS env vars10

2. Templating

#FeatureClass / FunctionChapter
7Frond Templatesres.render("page.frond", data)4
8Template Variables{{variable}}, {{nested.field}}4
9Template Includes{{> partial.frond}}4
10Template Helpers{{#if}}, {{#each}}, {{#unless}}4

3. Database and ORM

#FeatureClass / FunctionChapter
11Database ConnectionDatabase.getConnection(), .env config5
12Raw Queriesdb.fetchAll, db.fetchOne, db.execute5
13Named Parameters:paramName in SQL, bound from object5
14ORM Modelsclass Product extends Model6
15ORM CRUDModel.find, .save, .delete, .load6
16Query Builderdb.select().from().where().limit().fetch()7
17MigrationsAuto-migrations from model definitions5
18Sequence / next_idDatabase.get_next_id("table")5
19Multi-DB SupportSQLite, PostgreSQL, MySQL, MSSQL5

4. Authentication and Sessions

#FeatureClass / FunctionChapter
20JWT Authenticationauth middleware, req.user8
21Login / LogoutPOST /api/login, POST /api/logout8
22Password HashinghashPassword, verifyPassword8
23Sessionsreq.session.get/set, file/Redis/DB backends9
24Cookiesres.cookie, req.cookies, signed cookies9
25CSRF ProtectionCSRF middleware, csrfToken10

5. Background Processing

#FeatureClass / FunctionChapter
26Queue SystemQueue.push, .consume, .pop, .retry12
27Queue BackendsFile (default), RabbitMQ, Kafka, MongoDB12
28Service RunnerService, ServiceRunner26
29Scheduled Servicesinterval, runOnStart, restartDelay26

6. Caching

#FeatureClass / FunctionChapter
30Response Cache"ResponseCache:300" middleware11
31Cache APIcacheGet, cacheSet, cacheDelete11
32Cache BackendsMemory (default), Redis, file11
33Cache StatisticscacheStats()11

7. Communication

#FeatureClass / FunctionChapter
34Email (SMTP)Messenger class16
35WebSocketWebSocket server, ws.on, ws.send23
36Events SystemEvents.on, .emit, .once, .off, .clear13

8. Utilities and Services

#FeatureClass / FunctionChapter
37Structured LoggingLog.info/debug/warn/error, TINA4_LOG_LEVEL15
38LocalizationI18n, JSON locale files, t(key, vars)14
39API Clientapi singleton, get/post/put/delete21
40DI ContainerContainer, register, singleton, get, has25
41WSDL / SOAPWSDL.load, wsdl_operation, SOAP server24
42GraphQLSchema, resolvers, Router.graphql22

9. Developer Experience

#FeatureClass / FunctionChapter
43Swagger / OpenAPIAuto-generated from JSDoc @noauth, @path20
44Dev Dashboard/__dev — routes, queues, cache, logs29

2. Feature Details

Routing and HTTP

HTTP Routing — Define routes with Router.get("/path", handler). Handlers are async functions that receive (req, res). Supports all HTTP methods. Routes are auto-loaded from src/routes/.

Route Parameters — Typed parameters in curly braces: {id} is a string, {id:int} is an integer, {slug} matches URL-safe strings. Parameters are available as req.params.id.

Request and Responsereq.body is the parsed JSON request body. req.query holds query string values. res.json(data) sends JSON. res.render("template.frond", data) renders a template. res.status(404).json({}) chains status and body.

Middleware — Applied as a string in the route definition: Router.get("/path", handler, "auth,ResponseCache:300"). Multiple middleware separated by commas. Custom middleware registered with Router.middleware("name", fn).

Static Files — Everything in the public/ directory is served automatically. /public/logo.png is available at /logo.png.

CORS — Set TINA4_CORS_ORIGIN=* (or a specific domain) and TINA4_CORS_HEADERS to control which headers are allowed. Preflight OPTIONS requests are handled automatically.


Templating

Frond Templates — Tina4's built-in templating language. Files use the .frond extension. No separate template engine to install.

Template Variables{{variable}} renders a string. {{user.name}} accesses nested properties. {{price | currency}} applies a filter.

Template Includes{{> header.frond}} includes another template. Included templates share the same variable scope.

Template Helpers{{#if condition}}...{{/if}} for conditionals. {{#each items}}...{{/each}} for loops. {{#unless condition}} for negation.


Database and ORM

Database Connection — Configured via .env: TINA4_DB_DSN. Supports SQLite (sqlite:./data/app.db), PostgreSQL (pgsql:host=...), MySQL, and MSSQL. Accessed via Database.getConnection().

Raw Queriesdb.fetchAll(sql, params) returns an array of rows. db.fetchOne(sql, params) returns one row or null. db.execute(sql, params) runs a non-returning statement.

Named Parameters — Use :name in SQL. Pass values as { name: value }. Never interpolate user input directly into SQL -- always use named parameters.

ORM Models — Extend Model, declare fields. Tina4 generates the table if it does not exist. Product.find({ category: "Electronics" }) queries without SQL.

Query Builder — Chainable: .select("name", "price").from("products").where("active", true).orderBy("name").limit(20).fetch(). Composes complex queries without raw SQL.

Migrations — Tina4 compares the model definition to the live table schema and adds missing columns on startup. No migration files needed for additive changes.

Sequence / next_idDatabase.get_next_id("invoices") returns a race-safe, monotonically increasing ID using a sequence table. Safe for concurrent requests.

Multi-DB Support — Switch databases by changing TINA4_DB_DSN. Application code is unchanged.


Authentication and Sessions

JWT AuthenticationPOST /api/login with { username, password } returns a JWT. Include it as Authorization: Bearer <token>. Protected routes use the "auth" middleware string.

Login and Logout — Built-in login/logout routes. Customize by overriding the handlers. POST /api/logout invalidates the session.

Password HashinghashPassword(plain) returns a bcrypt hash. verifyPassword(plain, hash) validates. Never store plain passwords.

Sessionsreq.session.set("key", value) and req.session.get("key"). Backend: file (default), Redis (TINA4_SESSION_BACKEND=redis), or database.

Cookiesres.cookie("name", "value", { httpOnly: true, secure: true }) sets a cookie. req.cookies.name reads it.

CSRF Protection — The CSRF middleware validates a token on mutating requests. Include the token from req.csrfToken() in forms or AJAX calls.


Background Processing

Queue Systemqueue.push(payload) enqueues a job. queue.consume("topic") is a generator that yields jobs. Call job.complete() or job.fail() after each.

Queue Backends — File-based by default (TINA4_QUEUE_BACKEND=file). Switch to RabbitMQ, Kafka, or MongoDB with one env var change. No code changes.

Service RunnerServiceRunner manages multiple Service instances. Each runs its run() method on an interval. Crashes restart automatically.

Scheduled Services — Control timing with interval (ms), runOnStart (boolean), restartDelay (ms), and maxRestarts.


Caching

Response Cache"ResponseCache:300" as middleware caches the entire HTTP response for 300 seconds. Cache key includes the full URL with query parameters.

Cache APIcacheSet(key, value, ttlSeconds), cacheGet(key), cacheDelete(key). Use for custom caching logic: cache-aside, write-through, event-based invalidation.

Cache Backends — Memory (default), Redis (TINA4_CACHE_BACKEND=redis), file (TINA4_CACHE_BACKEND=file). Backend is transparent to application code.

Cache StatisticscacheStats() returns hits, misses, hit rate, entry count, and memory usage. Visible in the dev dashboard.


Communication

EmailMessenger reads SMTP config from .env. mailer.send({ to, subject, html, text }). Attachments supported. Dev mode intercepts emails and shows them in the dashboard.

WebSocket — Real-time bidirectional communication. Router.ws("/ws/chat", handler). ws.on("message", fn), ws.send(data), ws.broadcast(data).

Events System — In-process publish/subscribe. Events.on("event", handler, priority). Events.emit("event", payload). Events.once for one-shot listeners. Events.off and Events.clear for cleanup.


Utilities and Services

Structured LoggingLog.info/debug/warn/error(message, context). Outputs JSON. Level controlled by TINA4_LOG_LEVEL env var. Context fields merged into every log entry.

LocalizationI18n loads JSON locale files from locales/. i18n.t("key", { variable: "value" }) with interpolation. Automatic fallback to default locale for missing keys.

API Clientapi singleton from @tina4/core. api.configure({ baseUrl, headers, timeout }). Methods: api.get, api.post, api.put, api.patch, api.delete. Consistent response: { ok, status, data, error }.

DI ContainerContainer with register(name, factory) (transient) and singleton(name, factory). Resolve with get<Type>(name). has(name) for existence checks. reset() for test cleanup.

WSDL / SOAP — Consume SOAP with WSDL.load(url) and client.call(operation, params). Publish SOAP with wsdl_operation decorator and WSDL server class. Auto WSDL document generation.

GraphQL — Schema-first or code-first. Resolvers registered with Router.graphql. Introspection enabled in development. Playground available at /graphql.


Developer Experience

Swagger / OpenAPI — Routes annotated with JSDoc comments generate an OpenAPI 3.0 spec automatically. Swagger UI available at /swagger. @noauth marks public endpoints. @path, @query, and @body document parameters.

Dev Dashboard — Available at /__dev in development mode. Shows: registered routes, active queue jobs, cache entries and hit rates, recent log output, registered services and their status, environment variable summary.


3. Environment Variables Reference

env
# Server
TINA4_PORT=7145
TINA4_ENV=development

# Database
TINA4_DB_DSN=sqlite:./data/app.db

# Cache
TINA4_CACHE_BACKEND=memory
TINA4_CACHE_HOST=localhost
TINA4_CACHE_PORT=6379

# Queue
TINA4_QUEUE_BACKEND=file
TINA4_QUEUE_PATH=./data/queue

# Session
TINA4_SESSION_BACKEND=file
TINA4_SESSION_SECRET=your-secret-here

# Email
TINA4_MAIL_SMTP_HOST=smtp.example.com
TINA4_MAIL_SMTP_PORT=587
TINA4_MAIL_SMTP_USERNAME=noreply@example.com
TINA4_MAIL_SMTP_PASSWORD=your-app-password
TINA4_MAIL_SMTP_ENCRYPTION=tls

# Auth
TINA4_JWT_SECRET=your-jwt-secret
TINA4_JWT_EXPIRY=86400

# Logging
TINA4_LOG_LEVEL=info

# CORS
TINA4_CORS_ORIGIN=*
TINA4_CORS_HEADERS=Content-Type,Authorization

4. Package Imports Reference

typescript
// Core framework
import { Tina4, Router } from "tina4-nodejs";

// Database and ORM
import { Database } from "tina4-nodejs/orm";
import { Model } from "tina4-nodejs/orm";

// Auth
import { hashPassword, verifyPassword } from "tina4-nodejs";

// Cache
import { cacheGet, cacheSet, cacheDelete, cacheStats } from "tina4-nodejs";

// Queue
import { Queue } from "tina4-nodejs";

// Events
import { Events } from "tina4-nodejs";

// Logging
import { Log } from "tina4-nodejs";

// Localization
import { I18n } from "tina4-nodejs";

// Email
import { Messenger } from "tina4-nodejs";

// DI Container
import { Container } from "tina4-nodejs";

// Service Runner
import { Service, ServiceRunner } from "tina4-nodejs";

// WSDL / SOAP
import { WSDL, wsdl_operation } from "tina4-nodejs";

// API Client
import { api } from "@tina4/core";