The problem was that when I ran the method I had created for the insertion of new records in the database, it was an error. Researching, I approached the solution apparently. Apparently, it was a problem related to the CORS (Cross-Origin Resource Sharing), resulting in the error that I specified in the question.
My method for collecting data was this (NodeJS):
var newProyect = req.body;
proyect.create(newProyect, (err, proyect) => {
if(err){
res.status(500).send({message: 'Error al añadir el nuevo registro.'});
}else{
res.status(200).send({proyect: proyect});
}
});
and my model this (Angular):
export class Proyect{
constructor(
public _id: string,
public name: string,
public subName: string,
public description: string,
public author: string,
public date: string,
public campo: string
){
}
}
I realized that the property "_id" and "_v" are created automatically once they are registered in the database. And my model in NodeJs was this:
var mongoose = require('mongoose');
Schema = mongoose.Schema;
var proyectSchema = new Schema({
name: String,
subName: String,
description: String,
author: String,
date: String,
campo: String
});
module.exports = mongoose.model('proyect', proyectSchema);
What happened was that it sent a "project" object, created with the property "_id", although it was empty, it did not agree with the NodeJs model. With what it gave an error, an object with a property of more was created, and the server showed an internal error (500). Anyway, I needed the property "_id" to use it in one of the components of Angular, so I needed that property declared in the "Project" model, at least, with my knowledge, I came to the solution rethinking the collection method of data in the NodeJs controllers, leaving it like this:
function addProyect(req, res){
var params = req.body;
var proyect = new ProyectSchema();
proyect.name = params.name;
proyect.subName = params.subName;
proyect.description = params.description;
proyect.author = params.author;
proyect.date = params.date;
proyect.campo = params.campo;
proyect.save((err, proyectStored) => {
if(err){
res.status(500).send({message : 'Error al guardar el nuevo regitro.'});
}else{
res.status(200).send({proyect : proyectStored});
}
});
}
In this way, I collected only the data that I needed to enter a new record in the database. The field "_id" that still came empty emptied it, simply not using it.
I hope this helps someone. As for giving me a problem with CORS, it was because of a badly named route, but everything is fixed. Maybe it's a bad way to develop code, but hey, I'm taking out the chestnuts.
Greetings.