Registry / web-framework / trails

trails

JSON →
library3.2.2jsnpmunverified

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.

npm install trails
INSTALL
IMPORT
SIG · TRAILS
T
trails
web-frameworkjavascriptv3.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TrailsApp
const TrailsApp = require('trails')
import TrailsApp from 'trails'
Trails.js is primarily a CommonJS framework. The main 'trails' package exports the TrailsApp class, which is used to instantiate and bootstrap your application.
Controller
const { Controller } = require('trails')
class MyController extends Controller { ... }
While Trails v2.0+ made core classes like Controller globally available within the framework's runtime context, explicitly requiring them offers better clarity, IDE support, and ensures compatibility in environments where globals might not be reliably accessible.
Service
const { Service } = require('trails')
class MyService extends Service { ... }
Similar to Controller, the Service base class for creating application services is best imported explicitly using CommonJS `require` for improved code readability and maintainability, despite potential global availability.

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
trails --version
Debug
Known issues
breakingWith Trails v2.0, built-in Trails `Error` objects and resource classes (`Model`, `Controller`, `Service`, `Policy`) became globally accessible within the framework context. This changed how these core components were managed and accessed.
fix
Ensure your application code accounts for these classes potentially being global, or explicitly import them using `require('trails').ClassName` for better control and clarity.
affects: >=2.0
deprecatedThe `trailpack-core` module was deprecated in v2.0, with its functionality merged directly into the Trails core. Installing `trailpack-core@2.0` results in a no-op.
fix
Remove `trailpack-core` from your dependencies. Its features are now part of the main `trails` package.
affects: >=2.0
deprecatedIndividual modules like `trails-model`, `trails-service`, `trails-policy`, and `trails-controller` were merged into Trails core in v2.0 and deprecated as standalone packages.
fix
Discontinue use of these individual packages. The functionality is now available directly through the main `trails` package, often via `require('trails').ClassName` or implicitly within the framework's runtime.
affects: >=2.0
gotchaTrails.js requires Node.js version 7.6.0 or higher. Running with older Node.js versions will lead to syntax errors or unexpected behavior due to unsupported language features.
fix
Upgrade your Node.js environment to version 7.6.0 or newer. Use a tool like `nvm` (Node Version Manager) to easily manage multiple Node.js versions.
affects: <7.6.0
Errors
Common errors & fixes
Error: Cannot find module 'trails'
The `trails` package is not installed as a dependency in your project or the global `npm install -g trails` was not followed by `yo trails` to generate an application.
fix
Ensure `trails` is listed in your project's `package.json` and run `npm install`, or, for a new project, use `npm install -g yo generator-trails` followed by `yo trails` to scaffold an application.
TypeError: TrailsApp is not a constructor
Attempting to use ES Modules `import` syntax (`import TrailsApp from 'trails'`) with the `trails` package, which is primarily a CommonJS module.
fix
Use CommonJS `require` syntax: `const TrailsApp = require('trails')` to correctly import the TrailsApp class.
ReferenceError: Controller is not defined
This error typically occurs when a custom controller file extends `Controller` but is either not being loaded by the Trails.js framework or the `Controller` base class is not explicitly imported in a non-framework context.
fix
Ensure your controller file is located in the `api/controllers` directory of your Trails.js application. If using outside the framework's discovery mechanism, explicitly import `const { Controller } = require('trails')`.
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
trails — npm install trails · libregistry