forked from smit1678/dgm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.js
40 lines (35 loc) · 1.21 KB
/
user.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
35
36
37
38
39
40
var mongoose = require( 'mongoose' ),
db = require( './config/db' ),
User = require( './models/user' ),
name = ( process.argv[2] ) ? process.argv[2] : process.env.USER_NAME,
email = ( process.argv[3] ) ? process.argv[3] : process.env.USER_EMAIL,
pass = ( process.argv[4] ) ? process.argv[4] : process.env.USER_PASS,
type = ( process.argv[5] ) ? process.argv[5] : 0,
conn_str = 'mongodb://';
if ( db.user ) {
conn_str += db.user;
if ( db.pass ) {
conn_str += ':' + db.pass;
}
conn_str += '@';
}
conn_str += db.host + ':' + db.port + '/' + db.database;
mongoose.connect( conn_str );
User.create({
email : email,
name : name,
pass : pass,
type : type
}, function ( err, user ) {
if ( err || !user ) {
console.log( '============= ERROR ==============' );
console.log( err );
} else {
console.log( '============= USER ==============' );
console.log( 'Name - ' + user.name );
console.log( 'Email - ' + user.email );
console.log( 'Pass - ' + pass );
console.log( 'Type - ' + user.type );
}
process.exit();
});