This is my model with the scheme itself bd
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; And this is when I post a request, I'm trying to save all the data in the database
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); }); But what gives the console
{ 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 the data itself comes all well, but why doesn’t it want to accept the save method, do you have ideas ??