@mizuka-wu/ipc-express
v0.4.3
Published
This package enables you to use the electron ipc like an express application without the http overhead.
Readme
ipc-express
English
Express-like IPC communication for Electron applications. Use the familiar Express API style in Electron's main process without HTTP overhead.
Features
- 🚀 Express-like API - Familiar routing and middleware patterns
- 📦 Dual Module Support - CommonJS and ES Module
- 🔒 Type Safe - Full TypeScript support with generics
- 📚 Well Documented - Comprehensive guides and API documentation
- ⚡ Zero HTTP Overhead - Direct IPC communication
- 🎯 Modern Tooling - Built with Rolldown and TypeScript
Quick Start
Installation
pnpm add @mizuka-wu/ipc-expressMain Process
import { ipcMain } from 'electron';
import express from 'express';
import { IpcServer } from '@mizuka-wu/ipc-express/server';
const app = express();
const ipcServer = new IpcServer(ipcMain);
app.get('/api/users/:id', (req, res) => {
res.send({
id: req.params.id,
name: 'John Doe'
});
});
ipcServer.listen(app);Renderer Process
import { ipcRenderer } from 'electron';
import { IpcClient } from '@mizuka-wu/ipc-express/client';
interface User {
id: string;
name: string;
}
const client = new IpcClient(ipcRenderer);
async function getUser() {
const response = await client.get<User>('/api/users/1');
console.log(response.data.name); // 'John Doe'
}Documentation
License
中文
为 Electron 应用提供 Express 风格的 IPC 通信。在 Electron 主进程中使用熟悉的 Express API,无需 HTTP 开销。
特性
- 🚀 Express 风格 API - 熟悉的路由和中间件模式
- 📦 双模块支持 - CommonJS 和 ES Module
- 🔒 类型安全 - 完整的 TypeScript 支持和泛型
- 📚 文档完善 - 详细的指南和 API 文档
- ⚡ 零 HTTP 开销 - 直接 IPC 通信
- 🎯 现代工具链 - 使用 Rolldown 和 TypeScript 构建
快速开始
安装
pnpm add @mizuka-wu/ipc-express主进程
import { ipcMain } from 'electron';
import express from 'express';
import { IpcServer } from '@mizuka-wu/ipc-express/server';
const app = express();
const ipcServer = new IpcServer(ipcMain);
app.get('/api/users/:id', (req, res) => {
res.send({
id: req.params.id,
name: '张三'
});
});
ipcServer.listen(app);渲染进程
import { ipcRenderer } from 'electron';
import { IpcClient } from '@mizuka-wu/ipc-express/client';
interface User {
id: string;
name: string;
}
const client = new IpcClient(ipcRenderer);
async function getUser() {
const response = await client.get<User>('/api/users/1');
console.log(response.data.name); // '张三'
}文档
许可证
最后更新: 2024 年 3 月 19 日
