Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@terralang/terra
Advanced tools
The Modern Replacement for EJS: A powerful, fast, and flexible template engine with async support, middleware, error boundaries, and nested components
Terra is a powerful yet lightweight template engine for Node.js, Bun, Deno and more that supports async operations, middleware, error boundaries, and nested components - all powered by the Tereact Engine at the core.
npm install @terralang/terra
import Terra from '@terralang/terra';
// Initialize Terra with configuration
const terra = new Terra({
root: './views',
cache: true,
debug: true
});
// Render a template
const html = await terra.render('index.trx', {
title: 'My Page',
user: { name: 'John' }
});
Terra.js is built around several key concepts:
Terra accepts the following configuration options:
const terra = new Terra({
cache: boolean, // Enable template caching (default: true in production)
debug: boolean, // Enable debug logging (default: true in development)
errorBoundary: boolean, // Enable error boundaries (default: true)
middleware: Array, // Array of middleware functions
helpers: Object, // Object of helper functions
root: string // Root directory for templates
});
<%= value %>
<%= await asyncFunction() %>
<% if (condition) { %>
Content when true
<% } else { %>
Content when false
<% } %>
<% for (let item of items) { %>
<%= item %>
<% } %>
Components are reusable template pieces that can be imported and nested.
<!-- Header.trx -->
<header>
<h1><%= title %></h1>
<%= children %>
</header>
<!-- index.trx -->
import Header from './Header.trx'
<Header title="My Page">
<nav>Navigation content</nav>
</Header>
Components accept props as attributes:
<UserCard name="John" age={25} data={userData} />
Middleware functions process data before rendering:
terra.use(async (context) => {
// Modify or enhance context
context.timestamp = Date.now();
return context;
});
Helpers are utility functions available in templates:
terra.addHelper('formatDate', (date) => {
return new Date(date).toLocaleDateString();
});
// In template:
<%= helpers.formatDate(date) %>
Terra provides built-in error handling through error boundaries:
// Enable error boundaries in config
const terra = new Terra({
errorBoundary: true
});
// Errors will be caught and displayed in development
<%= potentially.invalid.expression %>
new Terra(options: TerraOptions)
render(path: string, data?: object): Promise<string>
Renders a template at the given path with optional data.
use(middleware: Function): Terra
Adds a middleware function to the stack.
addHelper(name: string, fn: Function): Terra
Adds a helper function for use in templates.
loadComponent(componentPath: string, parentPath?: string): Promise<string>
Loads a component from the filesystem.
Terra throws TerraError
with the following types:
INVALID_MIDDLEWARE
: Invalid middleware functionINVALID_HELPER
: Invalid helper functionCOMPONENT_NOT_FOUND
: Component file not foundEXPRESSION_ERROR
: Error in template expressionComponent Organization
Performance
Error Handling
Security
Terra respects the following environment variables:
NODE_ENV
: Controls default cache and debug settings
production
: Enables caching, disables debugdevelopment
: Disables caching, enables debugFAQs
The Modern Replacement for EJS: A powerful, fast, and flexible template engine with async support, middleware, error boundaries, and nested components
We found that @terralang/terra demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.