@xtaskjs/core
v1.0.22
Published
Core application runtime and DI container for xtaskjs.
Downloads
979
Readme
@xtaskjs/core
Core package for xtaskjs, a modern, fast Node.js web framework.
This package is part of the xtaskjs project, hosted at xtaskjs.io.
Installation
npm install @xtaskjs/coreUsage
import { ... } from '@xtaskjs/core';HTTP Platform Adapters
@xtaskjs/core now supports an adapter layer similar to NestJS. You can switch servers without changing controller code.
import { CreateApplication } from "@xtaskjs/core";
async function main() {
const app = await CreateApplication({
adapter: "node-http", // "express" | "fastify"
autoListen: true,
server: { host: "127.0.0.1", port: 3000 },
});
}With express or fastify, pass your instance in adapterInstance:
const app = await CreateApplication({
adapter: "express",
adapterInstance: express(),
});For Express support, install the adapter package:
npm install @xtaskjs/express-httpFor Fastify support, install the adapter package:
npm install @xtaskjs/fastify-httpRequest Validation
CreateApplication() now enables a global validation pipe by default. Controllers can bind DTOs directly from the request using the decorators exported by @xtaskjs/common:
import { Body, Controller, Param, Post } from "@xtaskjs/common";
import { IsString } from "class-validator";
class CreateUserDto {
@IsString()
name!: string;
}
@Controller("users")
class UsersController {
@Post("/:id")
create(@Param("id") id: string, @Body() body: CreateUserDto) {
return { id, body };
}
}Install the validator dependencies in the app workspace:
npm install class-transformer class-validatorTemplate Engines
Controllers can return rendered views with view(...):
import { view } from "@xtaskjs/core";
return view("home", { title: "Hello" });The selected adapter must implement view rendering (for example @xtaskjs/express-http via templateEngine).
Features
- Dependency Injection
- Application Lifecycle
- Kernel and Server utilities
Controller Route Integration
Container.registerLifeCycleListeners(app)now registers lifecycle handlers/runners and controller routes.ApplicationLifeCycle.registerControllerRoute(...)stores resolved routes.ApplicationLifeCycle.dispatchControllerRoute(method, path, ...args)executes guards, pipes, middlewares, and the route handler.
Metrics Log Configuration
- Metrics logs are disabled by default.
- Set
XTASKJS_SHOW_METRICS_LOGS=trueto show runtime metric logs like[Metrics] Heap MBandCPU { ... }.
Startup Benchmark
- Run
npm run benchmark:startup --prefix packages/corefrom the workspace root. - Optional env vars:
XTASKJS_BENCH_WARMUP(default:3)XTASKJS_BENCH_ITERATIONS(default:10)XTASKJS_BENCH_NODE_ENV(default:test)
- Example:
XTASKJS_BENCH_WARMUP=5 XTASKJS_BENCH_ITERATIONS=20 XTASKJS_BENCH_NODE_ENV=production npm run benchmark:startup --prefix packages/core
Resources
- Project site and documentation: xtaskjs.io
- npm package: @xtaskjs/core
- Source repository: xtaskjs/xtaskjs
