How to send response to the client from the server?

Good afternoon, I'm trying to send response to the client from the server node.js and get it through ajax. documentation express written, "if you want to answer with the data then use res.send() or res.json()." send the response via res.send()
exports.add = function (req, res, next) {
 if(req.body.input_project) {
 var newTask = new task();
 newTask.head.head_task = req.body.input_project;
 newTask.head.userID = req.user._id;
 newTask.save(function (err) {
 if (err)
 return next(err);
Res. status(204).send(newTask.id);
});
}else{
 return next();
}
};

get the answer
$.ajax({
 type: 'POST',
 url: '/TODOList',
 data: params,
 success: function(data,req,res) {
 console.log(data); //undenfined
addProject.call($target);
}
 })

Tell me what's wrong or how to handle the response? about dataType,I read that the ajax man will understand what it is, but also tried to specify the text, the result is the same - undenfined
June 27th 19 at 15:09
2 answers
June 27th 19 at 15:11
Solution
undenfined because you are sending code 204
204 No Content — the server successfully processed the request, but the response was transmitted to only the headers without the message body © wikipedia

Res. status(204).send(newTask.id);

try this:
Res. send(newTask.id);
You are right, thanks! - roselyn.Kozey39 commented on June 27th 19 at 15:14
June 27th 19 at 15:13
1) believe me that comes back, is there any response from the server(see the browser console)
2) check complete instead of success
3) check that all scripts will be executed on the server side. And that prints out(possibly a mistake).
Console checked, it's empty, the script to vyplesnetsya, data is written to the database function is activated when the request is successful, check for writes to complete principle the same as the browser console, the response body is empty - Object {readyState: 4, responseText: "", status: 204, statusText: "No Content"} - roselyn.Kozey39 commented on June 27th 19 at 15:16

Find more questions by tags jQueryJavaScriptExpress.jsNode.js