Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mongoose from 'mongoose';
- import bcrypt from 'bcryptjs';
- import 'mongodb';
- mongoose.connect('mongodb://localhost:27017/users');
- mongoose.connection;
- var UserSchema = mongoose.Schema({
- name: {
- type: String,
- index: true
- },
- username: {
- type: String
- },
- password: {
- type: String
- },
- email: {
- type: String
- }
- });
- var User = module.exports = mongoose.model('User', UserSchema);
- function createUser(newUser, callback) {
- bcrypt.genSalt(10, function(err, salt) {
- bcrypt.hash(newUser.password, salt, function(err, hash) {
- newUser.password = hash;
- return newUser.save(callback);
- });
- });
- }
- module.exports = createUser;
- var newUser = new User({
- name: name,
- email: email,
- username: username,
- password: password
- });
- User.createUser(newUser, function(err, user) {
- if(err) throw err;
- console.log(user);
- });
- { name: 'name',
- user_name: 'Aleksey Bilous',
- user_email: 'alekseybilous@gmail.com',
- user_pass: '1',
- user_passConf: '1' }
- /home/leha/Desktop/Projects/test/models/user.js:44
- return newUser.save(callback);
- ^
- TypeError: newUser.save is not a function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement