# dr-server **Repository Path**: the-mandalorian/dr-server ## Basic Information - **Project Name**: dr-server - **Description**: node服务端 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-02-28 - **Last Updated**: 2022-01-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DrinkRecord Server 服务端工程 服务器地址 `ubuntu@118.126.101.112` - 测试服地址 https://drtest.rustfisher.com - 正式服地址 https://dr.rustfisher.com 可以访问[https://drtest.rustfisher.com/v1/info](https://drtest.rustfisher.com/v1/info)查看测试服信息 使用框架 - nodeJS - mongodb ## 接口 - [x] 保存饮用记录(新增/修改) - [x] 查询饮用记录 - [x] 删除饮用记录 ## DrinkRecord Server 测试服 需要在代码根目录放一个配置文件`localCfg.js` 例如测试服使用服务器的`8086`端口 ```js module.exports = { SERVER_PORT: 8086, DB_ADDR: 'mongodb://127.0.0.1:1993/drinkRecordDebug', SERVER_RUN_TYPE: 'debug' } ``` 正式服使用`8085`端口 ## express router的url一定要是`/`开头 例如 ```js router.get('/info', async (req, res) => { let msg = 'DrinkRecord Server Version: v1' let resp = { 'status': 1, 'msg': 'ok', 'data': msg } res.send(resp) }) ``` ## 不要用vscode连服务器 vscode连接到服务器,服务器cpu飙到100%。 最好是代码在电脑本地修改,改完了再上传。 ## npm包 ``` cnpm i express@next mongoose cors cnpm i nodemon cnpm i http-assert ``` ## 操作mongodb Ubuntu操作mongodb的[官方文档](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/) 配置文件`/etc/mongod.conf` 把端口改为1993,服务器防火墙记得允许1993端口 ```bash sudo ufw allow 1993 ``` 服务器使用的是`systemctl` 启动mongodb ```bash sudo systemctl start mongod ``` 查看状态 ```bash sudo systemctl status mongod ``` 重启 ```bash sudo systemctl restart mongod ``` ## 使用pm2管理服务 在服务器代码根目录,启动服务 ``` pm2 start index.js ``` 停止服务 ``` pm2 stop index ``` 代码更新后,要重启服务 ``` pm2 restart index.js ``` 启动正是站的时候,给服务一个别名 ``` pm2 start index.js --name="dr-release" ```