
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
@hestjs/core
Advanced tools
HestJS Core Framework - A TypeScript framework built on Hono with dependency injection and decorators
HestJS 核心包 - 基于 Hono 构建的现代化 TypeScript 后端库,提供装饰器驱动的开发体验和依赖注入系统。
hestjs.config.ts这样的配置文件,无需任何配置npm install @hestjs/core
# 或
yarn add @hestjs/core
# 或
bun add @hestjs/core
在此之前你应该在tsconfig中添加以下内容:
{
"compilerOptions": {
...
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true
}
}
import { Controller, Get, HestFactory, Module } from "@hestjs/core";
@Controller("/")
export class WelcomeController {
@Get("/welcome")
async welcome() {
return "Welcome to HestJS!";
}
}
@Module({
controllers: [WelcomeController],
providers: [],
imports: [],
exports: [],
})
export class AppModule {}
async function bootstrap() {
const app = await HestFactory.create(AppModule);
const hono = app.hono();
Bun.serve({
port: 3000,
fetch: hono.fetch,
});
}
bootstrap();
import { Controller, Get, Post, Context, Body, Param } from "@hestjs/core";
import type { HestContext } from "@hestjs/core";
@Controller("/users")
export class UsersController {
@Get("/")
async getAllUsers() {
return { message: "Get all users" };
}
@Get("/:id")
async getUser(@Param("id") id: string, @Context() c: HestContext) {
return { id, message: `Get user ${id}` };
}
@Post("/")
async createUser(@Body() body: any, @Context() c: HestContext) {
return { message: "User created", data: body };
}
}
import { Module } from "@hestjs/core";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";
@Module({
controllers: [UsersController],
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
import { injectable } from "@hestjs/core";
@injectable()
export class UsersService {
findAll() {
return [
{ id: 1, name: "John" },
{ id: 2, name: "Jane" },
];
}
findOne(id: number) {
return { id, name: `User ${id}` };
}
}
HestJS Core 包含以下主要模块:
@hestjs/core/
├── application/ # 应用工厂和实例
│ ├── HestFactory # 应用工厂
│ └── HestApplicationInstance # 应用实例
├── decorators/ # 装饰器系统
│ ├── @Controller # 控制器装饰器
│ ├── @Module # 模块装饰器
│ ├── @injectable # 可注入装饰器
│ └── 路由装饰器 # @Get, @Post, @Put, @Delete, @Patch
├── container/ # 依赖注入容器
├── router/ # 路由系统
├── exceptions/ # 异常处理
├── interceptors/ # 拦截器
├── interfaces/ # 类型定义
└── utils/ # 工具函数
HestFactory.create(moduleClass)创建应用实例的静态方法。
import { HestFactory } from "@hestjs/core";
import { AppModule } from "./app.module";
const app = await HestFactory.create(AppModule);
@Controller(path?: string)定义控制器类和基础路径。
@Controller("/api/users")
export class UsersController {
// 控制器方法
}
@Get(path?: string) - GET 请求@Post(path?: string) - POST 请求@Put(path?: string) - PUT 请求@Delete(path?: string) - DELETE 请求@Patch(path?: string) - PATCH 请求@Controller('/users')
export class UsersController {
@Get('/') // GET /users/
@Get('/:id') // GET /users/:id
@Post('/') // POST /users/
@Put('/:id') // PUT /users/:id
@Delete('/:id') // DELETE /users/:id
@Patch('/:id') // PATCH /users/:id
}
@Context()获取完整的 Hono Context 对象。
@Get('/')
async getUsers(@Context() c: HestContext) {
// 访问所有 Hono Context 功能
const userAgent = c.req.header('User-Agent');
return c.json({ message: 'Hello' });
}
@Body()获取请求体数据。
@Post('/')
async createUser(@Body() userData: CreateUserDto) {
return userData;
}
@Param(key?: string)获取路径参数。
@Get('/:id')
async getUser(@Param('id') id: string) {
return { id };
}
@Query(key?: string)获取查询参数。
@Get('/')
async getUsers(@Query('page') page: string) {
return { page };
}
@Header(key?: string)获取请求头。
@Get('/')
async getUsers(@Header('authorization') auth: string) {
return { auth };
}
@Module(options)定义模块和依赖关系。
interface ModuleOptions {
imports?: any[]; // 导入的模块
controllers?: any[]; // 控制器
providers?: any[]; // 提供者(服务)
exports?: any[]; // 导出的提供者
}
@Module({
imports: [DatabaseModule],
controllers: [UsersController],
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
@injectable()标记类为可注入的服务。
@injectable()
export class UsersService {
constructor(private readonly databaseService: DatabaseService) {}
}
const app = await HestFactory.create(AppModule);
// 添加全局拦截器
app.useGlobalInterceptors(new ValidationInterceptor());
app.useGlobalInterceptors(new ResponseInterceptor());
const app = await HestFactory.create(AppModule);
// 添加全局异常过滤器
app.useGlobalFilters(new HttpExceptionFilter());
HestJS 不会封装 Hono,你可以直接使用所有 Hono 功能:
const app = await HestFactory.create(AppModule);
const honoApp = app.hono();
// 使用 Hono 原生中间件
honoApp.use(cors());
honoApp.use("/api/*", async (c, next) => {
console.log(`${c.req.method} ${c.req.url}`);
await next();
});
// 添加自定义路由
honoApp.get("/health", (c) => c.text("OK"));
提供完整的 Hono Context 类型安全:
import type { HestContext } from '@hestjs/core';
@Get('/')
async handler(@Context() c: HestContext) {
// 完整的 Hono Context API
const method = c.req.method;
const url = c.req.url;
const headers = c.req.header();
return c.json({ method, url });
}
HestFactory.create()@Controller() 装饰器@Get(), @Post(), @Put(), @Delete(), @Patch()@Context(), @Body(), @Param(), @Query(), @Header()@Module() 装饰器@UseMiddleware() 装饰器@UseGuards() 装饰器@UsePipes() 装饰器欢迎提交 Issue 和 Pull Request!
更多信息:
FAQs
HestJS Core Framework - A TypeScript framework built on Hono with dependency injection and decorators
The npm package @hestjs/core receives a total of 17 weekly downloads. As such, @hestjs/core popularity was classified as not popular.
We found that @hestjs/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.