I close the node terminal by mistake in the angle service create

0

When I save something to the bd (MongoDB) from the app, I close the node server in the terminal, however it saves the data.

I have in the file api_v1.js:

const express = require('express');
const router = express.Router();

const Profesor = require('../models/profesor');

router.post('/profesores', (req, res) => {
    delete req.body._id;
    Profesor.create(req.body, (err, Profesor) =>{
        if(err){
            res.json(err)
        }else{
            res.json(profesor);
        }
    });
});

On the browser terminal:

    Source map error: TypeError: NetworkError when attempting to fetch resource.
Resource URL: http://localhost:3000/main.bundle.js
Source Map URL: main.bundle.map[Learn More]

In the node console it says:

C:\Users\leand\Documents\Universidad\Software III\PracticasProyecto\colegio-crud-app\node_modules\mongodb\lib\utils.js:132
      throw err;
      ^

ReferenceError: profesor is not defined
    at Profesor.create (C:\Users\leand\Documents\Universidad\Software III\PracticasProyecto\colegio-crud-app\routes\api_v1.js:20:22)
    at Function.<anonymous> (C:\Users\leand\Documents\Universidad\Software III\PracticasProyecto\colegio-crud-app\node_modules\mongoose\lib\model.js:3954:16)...
    
asked by Kraken 06.05.2018 в 01:56
source

1 answer

0

When a critical error occurs, the node server is stopped by execution error. 1st It saves you in database because the problem is in the response of the function not in the insertion in database 2nd The error indicates that the teacher variable is not defined, because this variable does not exist and can not parse the answer to json of something that does not exist, the solution would be to send res.json (Teacher); Professor is the promise that the create returns. I hope this helps you. Greetings

    
answered by 06.05.2018 в 12:10