-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-init.js
34 lines (31 loc) · 1.02 KB
/
user-init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const config = require(__dirname + '/config.js')
const mongoose = require("mongoose")
const User = require('./src/models/user')
mongoose.Promise = global.Promise
mongoose.connect("mongodb://" + config.db.username + ":" + config.db.password +
"@" + config.db.host + ":" + config.db.port + "/" + config.db.name,
{ useMongoClient: true },
function(error) {
if(error) {
console.log(error)
process.exit(1)
}
else {
console.log("Connection to the database successful.")
const userData = {
email: config.user.email,
password: config.user.password,
username: config.user.username
}
User.create(userData, function (error, user) {
if (error) {
console.log('Error:', error)
}
else {
console.log('User successfully created.')
}
process.exit()
});
}
}
)