I am using JS to perform an API and as much as I try I can not understand why, when making a POST request to create a user, it tells me that User is not a constructor.
I am "new" in JS and I have in mind the creation of classes / constructors that use Java, so I do not understand why in JS it does not work in the same way . Maybe I miss something or maybe I do not understand it well .
I have attached the code with which I am working as an example to try to understand it:
As a database I use MONGO
'use strict'
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var usuarioSchema = Schema({
name: String,
surname: String,
companyName: String
//id: Integer,
//telephone: Integer,
//data: String
});
module.export = mongoose.model('Usuario', usuarioSchema);
This would be the file where I supposedly kept the user in my database.
'use strict'
var Usuario = require('../Usuario.js');
function saveUsuario(request, res) {
var usuario = new Usuario();
var params = request.body;
usuario.name = params.name;
usuario.surname = params.surname;
usuario.companyName = params.companyName;
usuario.save(function (err, usuarioStored) {
if (err) { //Si se producen errores al guardar un usuario
res.status(500).send({
message: 'Error al guardar el usuario'
});
} //Si no se producen errores al guardar
res.status(200).send({
usuario: usuarioStored
});
});
}
By using some HTTP request software (I use POSTMAN ) it tells me that User is not a constructor. I can not understand why it is not a constructor if I am actually saving a new User in my database with the three specified fields.