-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadduser.js
More file actions
42 lines (28 loc) · 977 Bytes
/
Copy pathadduser.js
File metadata and controls
42 lines (28 loc) · 977 Bytes
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
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var password = require('password-hash-and-salt');
rl.question("Username: ", (username) => {
rl.question("Password: ", (pass) => {
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/shared-premium');
var db = require('mongoose').connection;
db.on('error', console.error.bind(console, 'connection error:'));
var User = require('./api/models/userModel');
var user = new User({
username: username,
is_admin: false
});
password(pass).hash(function (error, hash) {
if (error) throw error;
user.password_hash = hash;
user.save(function (err) {
if (err) throw err;
console.log('saved');
process.exit();
});
});
})
})