@evjs/server

中文文档
0.3.30发布于 2026/11/14MITTypeScriptES Module构建来源已验证近 30 天下载 2877

Server-side runtime for the evjs framework

原始使用文档
文档目录11 节
  1. Features
  2. Install
  3. Quick Start
  4. 1. Server Routes
  5. 2. Server Functions
  6. Runtime Adapters
  7. Node.js
  8. Fetch (Deno/Bun/Edge)
  9. Core APIs
  10. Routing
  11. License

@evjs/server

Server runtime core for the evjs framework and standalone Hono/fetch apps.

Features

  • Hono-based — Build RESTful APIs alongside your React application.
  • Server Function Support — Seamlessly handle "use server" function calls with type safety.
  • Standard Request/Response — createRoute() factory for simplified API endpoint creation.
  • Multi-Runtime — First-class support for Node.js and standard Fetch runtimes (Deno, Bun, Cloudflare Workers).

Install

npm install @evjs/server

Quick Start

1. Server Routes

Create standard REST endpoints using the createRoute() factory:

// src/routes/users.ts
import { createRoute } from "@evjs/server";

export const usersRoute = createRoute("/api/users", {
  GET: async (_request) => Response.json([{ id: 1, name: "Alice" }]),
});

The path must be a string literal so the route definition keeps precise compile-time types. Register the route explicitly in the standalone app:

// src/app.ts
import { createApp } from "@evjs/server";
import { usersRoute } from "./routes/users.js";

export const app = createApp({ routes: [usersRoute] });

This programmatic API is independent from evjs Framework file routes anchored at src/apis/**/api.*; the framework does not scan createRoute() declarations.

2. Server Functions

Framework projects use the "use server" directive in reachable modules. The generated server entry creates an application-owned function registry and registers every discovered export. .server.ts is the recommended naming convention, not a discovery rule:

// src/posts.server.ts
"use server";

export async function getPosts() {
  // Query DB or third-party API
  return [{ id: 1, title: "Hello World" }];
}

Standalone apps register their function implementations explicitly. The same registry can dispatch calls for a custom WebSocket or IPC transport:

import { createApp, createServerFunctionRegistry } from "@evjs/server";
import { getPosts } from "./posts.server.js";

const serverFunctions = createServerFunctionRegistry();
serverFunctions.register("posts:getPosts", getPosts);

export const app = createApp({ serverFunctions });

Registries are isolated per app, so two apps in one process may safely use the same function id for different implementations.

Runtime Adapters

Node.js

import { serve } from "@evjs/server/node";
import { app } from "./app";

serve(app, { port: 3001 });

Fetch (Deno/Bun/Edge)

@evjs/server/fetch provides the zero-configuration empty app. When a standalone app owns routes or server functions, export that app's handler:

import { app } from "./app.js";

Deno.serve({ port: 3001 }, app.fetch);

Worker-style hosts that discover named module exports can use the same handler:

import { app } from "./app.js";

export const fetch = app.fetch;
export default { fetch };

Core APIs

Routing

  • createRoute(path, handler): Create a REST endpoint.
  • createApp(options): Main application factory.
  • createServerFunctionRegistry(): Create an isolated function registry for one application or custom transport.

Application-facing server runtime APIs are exported from @evjs/server and its runtime subpaths. Use @evjs/ev when the app needs framework composition such as file-route discovery, server-function transforms, SSR/PPR/RSC build validation, manifests, or deployment artifacts.

License

MIT

版本与发布记录

@evjs/server 共发布 97 个版本,首次发布于 2026/03/24;过去 12 个月发布了 97 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.30latest2026/11/14今天
0.3.30-alpha.1alpha2026/11/122 天前
0.3.30-alpha.02026/11/113 天前
0.2.18legacy2026/11/0212 天前
0.3.292026/11/0113 天前
0.3.282026/10/3114 天前

关于 @evjs/server 的常见问题

@evjs/server 是什么?

Server-side runtime for the evjs framework

如何安装 @evjs/server?

在项目目录运行 npm install @evjs/server,或使用 pnpm add / yarn add / bun add。

@evjs/server 支持 TypeScript 吗?

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

@evjs/server 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@evjs/server 可以商用吗?

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

@evjs/server 的下载量有多少?

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

@evjs/server 还在维护吗?

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