feat(env): 添加环境变量配置并初始化项目

- 新增 .env 文件,定义服务器端口和 IP 地址
- 创建 .gitignore 文件,忽略 node_modules 目录
- 修改 start.js,从环境变量中读取配置
- 初始化 package-lock.json 和 package.json
- 添加 dotenv 依赖用于加载环境变量
This commit is contained in:
2025-04-09 11:01:02 +08:00
parent c50dbd5b18
commit d1643f054e
5 changed files with 43 additions and 2 deletions

View File

@@ -1,6 +1,11 @@
require('dotenv').config(); // 引入dotenv库并加载.env文件中的环境变量
const GateServer = require('./index');
const server = new GateServer(8080, '127.0.0.1');
// 从环境变量中读取端口和IP地址
const port = parseInt(process.env.GATE_PORT, 10);
const host = process.env.GATE_HOST;
const server = new GateServer(port, host);
server.on('connection', (socket) => {
console.log('A new client has connected');