@devbie/newbie

中文文档
1.17.0发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 4498

newbie backend framework runtime

原始使用文档
文档目录10 节
  1. Features
  2. Requirements
  3. Installation
  4. Quick start
  5. NewbieFactory options
  6. What the framework wires for you
  7. List endpoints and query pipes
  8. Environment variables
  9. Related packages
  10. License

@devbie/newbie

npm version license

A batteries-included backend application framework runtime built on top of NestJS 11, Prisma 7 and Express 5. Newbie gives you a production-ready bootstrap in a single call — security middleware, validation, cursor pagination pipes, a layered exception-filter chain, extended Prisma access and optional self-reporting — without forcing you to wire it all together.

Features

  • One-call bootstrap — NewbieFactory.create() configures CORS, cookie parsing, body parsers, the global ValidationPipe, Helmet (production) and Swagger (development), then starts the HTTP server.
  • Global framework module — FrameworkModule.forRoot() installs config loading, rate limiting, HttpModule, a unified response interceptor and a five-layer exception-filter chain.
  • Extended Prisma integration — supply your generated PrismaClient and get a global PrismaService that supports client extensions registered after module initialization.
  • Query parameter pipes — cursor pagination, cursor slug, ordering and select/include/where parsing for Prisma-driven list endpoints.
  • Shared DTOs and utilities — pagination request/response DTOs plus crypto, datetime, array and other common helpers.
  • Observability built in — graceful shutdown with bounded request draining, watch-mode port-race recovery, and env-gated backend monitor probe (BACKEND_MONITOR_ENDPOINT + BACKEND_MONITOR_TOKEN) and module-hub reporter (MODULE_HUB_ENDPOINT + MODULE_HUB_TOKEN).

Requirements

@devbie/newbie is a runtime library; NestJS, Prisma and related packages are declared as peer dependencies so your project controls their versions:

Peer dependencyVersion
@nestjs/common^11.0.0
@nestjs/core^11.0.0
@nestjs/platform-express^11.0.0
@nestjs/config^4.0.0
@nestjs/swagger^11.0.0
@nestjs/throttler^6.0.0
@nestjs/axios^4.0.0
@prisma/client^7.0.0
@prisma/adapter-pg^7.0.0
express^5.0.0

Installation

npm install @devbie/newbie

Quick start

Register FrameworkModule.forRoot() in your root module and pass your generated PrismaClient constructor:

// src/application/application.module.ts
import { Module } from "@nestjs/common";
import { FrameworkModule } from "@devbie/newbie";
import { PrismaClient } from "@generated/prisma/client";
import { ApplicationController } from "./application.controller";

@Module({
  imports: [FrameworkModule.forRoot({ prisma: { PrismaClient } })],
  controllers: [ApplicationController],
})
export class ApplicationModule {}

Then bootstrap with NewbieFactory:

// src/main.ts
import { NewbieFactory } from "@devbie/newbie";
import { ApplicationModule } from "./application/application.module";

async function bootstrap(): Promise<void> {
  await NewbieFactory.create(ApplicationModule, {
    swagger: { title: "My API" },
  });
}

void bootstrap();

The fastest way to get this structure is to scaffold a project with the companion CLI:

npx @devbie/newbie-cli create my-app

NewbieFactory options

NewbieFactory.create(rootModule, options) accepts the following options (every field is optional):

OptionTypeDefaultDescription
environmentstringENVIRONMENT or developmentdevelopment enables Swagger; production enables Helmet.
portnumberPORT or 3000Port the HTTP server listens on.
corsAllowedOriginsstring[]ALLOWED_ORIGINSAllowed CORS origins (credentials enabled).
bodyLimitstring10mbMaximum request body size.
requestTimeoutnumber60000Request timeout in milliseconds.
keepAliveTimeoutnumber—Keep-alive timeout in milliseconds.
loggerstring[]LOG_LEVEL or ['log','warn','error']NestJS log levels.
swaggerobject | falseenabled in developmentSwagger config (title, description, version, path, default path /api).
portRaceRecoverybooleanenvironment !== "production"Survive port races during nest start --watch under bind mounts.
shutdownTimeoutMsnumber10000Grace period for in-flight requests on SIGTERM/SIGINT.
clusterbooleanfalseRun one worker per available CPU core.

What the framework wires for you

  • cookie-parser, JSON/URL-encoded body parsers, and always-on text/plain parsing (monitor SDKs report via navigator.sendBeacon).
  • CORS with credentials, plus the v4 (extended) Express query parser. Routes decorated with @AllowAnyOrigin() answer Access-Control-Allow-Origin: * (preflight included) while every other route keeps the origin whitelist.
  • A global ValidationPipe with transform and whitelist enabled.
  • Helmet in production; Swagger UI (cookie + bearer auth) in development.
  • A global throttler guard (10000 requests / second per endpoint by default).
  • A response-shaping HttpResponseInterceptor.
  • Exception filters in priority order: throttler → Prisma → newbie → HTTP → catch-all, so every failure gets a consistent error envelope.
  • Env-gated reporters after listen: heartbeat (HEARTBEAT_*), module-hub (MODULE_HUB_*) and dependency health (HEALTH_*; checks always run, the POST is skipped when the endpoint is unset).

List endpoints and query pipes

Newbie ships pipes that translate query parameters into Prisma arguments:

  • WherePipe — parse a where query parameter into a Prisma filter.
  • OrderByPipe — parse ordering parameters.
  • SelectIncludePipe — parse select / include parameters.
  • CursorPipe / CursorSlugPipe — keyset (cursor) pagination parameters.

Shared DTOs (CommonListRequestDto, CommonListResponseDto, CommonGetByStringIdRequestDto, CommonGetByNumberIdRequestDto) keep list endpoints consistent across modules. The @Cookies() parameter decorator provides typed access to request cookies.

Environment variables

VariableUsed for
ENVIRONMENTdevelopment or production.
PORTHTTP listen port.
ALLOWED_ORIGINSComma-separated CORS origin list.
LOG_LEVELComma-separated NestJS log levels (e.g. log,warn,error).
MODULE_HUB_ENDPOINTFull report URL; enables module-hub self-reporting when set together with MODULE_HUB_TOKEN.
MODULE_HUB_TOKENToken sent to the module hub.

When both MODULE_HUB_ENDPOINT and MODULE_HUB_TOKEN are present, the framework automatically sends a full snapshot on boot and a ping every 60 seconds. Reporting is fire-and-forget and never blocks application startup.

License

MIT

版本与发布记录

@devbie/newbie 共发布 33 个版本,首次发布于 2026/09/25;过去 12 个月发布了 33 个版本。

版本发布日期距今
1.17.0latest2026/11/093 天前
1.16.02026/11/093 天前
1.15.02026/11/093 天前
1.14.02026/11/093 天前
1.13.22026/11/093 天前
1.13.12026/11/093 天前

关于 @devbie/newbie 的常见问题

@devbie/newbie 是什么?

newbie backend framework runtime

如何安装 @devbie/newbie?

在项目目录运行 npm install @devbie/newbie,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(^7.0.0)、express(^5.0.0)、@nestjs/core(^11.0.0 || ^12.0.0)、@nestjs/axios(^4.0.0 || ^12.0.0)、@nestjs/common(^11.0.0 || ^12.0.0)、@nestjs/config(^4.0.0 || ^12.0.0)、@prisma/client(^7.0.0)、@nestjs/swagger(^11.0.0 || ^12.0.0)、reflect-metadata(^0.1.12 || ^0.2.0)、@nestjs/throttler(^6.0.0)、@prisma/adapter-pg(^7.0.0)、@nestjs/platform-express(^11.0.0 || ^12.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devbie/newbie 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devbie/newbie 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@devbie/newbie 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@devbie/newbie 可以商用吗?

@devbie/newbie 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devbie/newbie 的下载量有多少?

根据 npm 官方下载统计,@devbie/newbie 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,498 次,日均约 150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devbie/newbie 还在维护吗?

最新版本 1.17.0 发布于 2026/11/09(3 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/09/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。