Skip to content

Commit 9a60079

Browse files
committed
[add]mongo生产开发区分
1 parent 606b492 commit 9a60079

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/config.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
const env = process.env.NODE_ENV || 'development';
1+
const env = process.env.NODE_ENV;
22
const port = 1244
3+
const db = '/test'
34
let baseUrl = ''
4-
if(env === 'development'){
5-
baseUrl = 'http://127.0.0.1'
5+
if(env){
6+
baseUrl = 'mongodb://127.0.0.1:27017'
67
}else{
7-
baseUrl = '待上线'
8+
console.log('----------------------')
9+
baseUrl = 'mongodb://47.95.203.205:27017'
810
}
11+
console.log(baseUrl,'----------------------')
912
module.exports = {
1013
port,
11-
baseUrl
14+
baseUrl,
15+
db
1216
}

lib/mongoDB.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// 用于定义数据表结构
22
const mongoose = require('mongoose')
3+
const {baseUrl,port, db} = require('./config')
4+
const url = baseUrl+db
5+
console.log(url)
36
mongoose.set('strictQuery', false);
47
exports.connect = () => {
5-
mongoose.connect('mongodb://127.0.0.1/test')
8+
mongoose.connect(url)
69
.then(() => {
710
console.log('数据库连接成功')
811
})

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"dev": "nodemon app.js"
8+
"dev": "set NODE_ENV=development && nodemon app.js",
9+
"server": "set NODE_ENV=production && nodemon app.js"
910
},
1011
"keywords": [],
1112
"author": "",

0 commit comments

Comments
 (0)