Trails.js Web Application Framework

3.2.2 · active · verified Sun Apr 19

Trails.js is a modern, community-driven web application framework for Node.js, currently at version 3.2.2. It emphasizes a convention-based, API-driven design philosophy, inspired by frameworks like Ruby on Rails and Grails. Trails.js accelerates development through scaffolding provided by Yeoman and extends its capabilities via 'Trailpacks'—modular extensions that integrate existing ecosystem tools like Hapi, Express, Waterline, or Knex. The framework supports microservices architectures and is designed to work across Windows, Mac, and Linux, requiring Node.js 7.6.0 or newer. Its release cadence is stable, with major version updates occurring less frequently, focusing on stability and core enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to scaffold a new Trails.js application using Yeoman, create a basic controller, define a route, and start the server to serve a simple 'Hello World' response.

#!/usr/bin/env sh
# First, install the global tools needed to scaffold a Trails app
npm install -g yo generator-trails

# Create a new Trails project (choose a 'web' or 'api' template)
yo trails my-trails-app
cd my-trails-app

# Example of a simple controller (api/controllers/HelloController.js)
# Note: `Controller` is implicitly available via the framework context.
printf "'use strict'\n\nmodule.exports = class HelloController extends Controller {\n  greet (request, reply) {\n    reply.send('Hello from Trails.js!')\n  }\n}" > api/controllers/HelloController.js

# Example of adding a route (config/routes.js)
# Add this route to the `module.exports.routes` object in config/routes.js
# {\n#   '/hello': {\n#     handler: 'HelloController.greet',\n#     method: 'GET'\n#   }\n# }

# Now, run your Trails application
node server.js

# Open your browser or use curl to visit http://localhost:3000/hello

view raw JSON →