Skip to content

快速开始

方式一:二进制部署(推荐)

无需安装 Node.js,下载即用。

1. 获取二进制文件

从项目 server/dist/ 目录获取对应平台的可执行文件:

平台文件
macOS (Apple Silicon)im-server-mac
Linux (x64)im-server
Windows (x64)im-server.exe

2. 启动服务

将二进制文件和 run.js 放在同一目录,然后执行:

bash
# macOS / Linux
node run.js

# Windows
node run.js

服务启动后会自动在当前目录创建 im.db 数据库文件,并在控制台输出 API Key:

[IM Server] Security config initialized.
[IM Server] API Key: •••••••••••••••• (shown in full on first run)
[IM Server] Listening on port 3000

重要

首次启动时请记录完整的 API Key,后续管理员接口需要使用。

3. 验证服务

bash
# 注册用户
curl -X POST http://localhost:3000/api/register \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"123456","nickname":"管理员"}'

# 登录获取 Token
curl -X POST http://localhost:3000/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"123456"}'

方式二:源码部署

1. 环境准备

确保已安装 Node.js >= 14。

2. 安装依赖

bash
cd server
npm install

3. 启动开发模式

bash
npm run dev

生产模式使用:

bash
npm start

4. 构建前端(可选)

如果需要将前端构建产物部署到 IM 后端的静态目录下:

bash
cd uniapp
npm run build
# 或
npm run build:build

构建脚本会自动将产物复制到 server/public/ 目录。

前端开发

1. 安装依赖

bash
cd uniapp
npm install

2. 配置环境

编辑 config/dev.js,设置正确的后端地址:

javascript
export default {
  baseURL: 'http://localhost:3000',       // 主后端地址
  imBaseURL: 'http://localhost:3000/api', // IM 后端 API 地址
  imWsURL: 'ws://localhost:3000'          // IM WebSocket 地址
}

3. 启动开发服务器

bash
npm run dev:h5

默认在 http://localhost:8086 启动。

下一步