Your callback should take in req
and res
, but is currently only taking in req
as res
.
app.post('/:tableName', function(req, res){
should give the function what it expects.
Question
I found this example to get body, but how can I retrive the req.param variable? I do not have req in this case?!
app.post('/:tableName', function(res){
var data = '';
res.on('data', function (chunk){
data += chunk;
});
res.on('end',function(){
var obj = JSON.parse(data);
var schema = require('./schema/' + req.param('tableName'));
var record = new schema(obj);
record.save(function(err) {
if (err) {
console.log(err);
res.status(500).json({status: 'failure'});
} else {
res.json({status: 'success'});
}
});
})
});
UPDATE
I modified the method signature like this, but then first res.on
will not get called.
app.post('/:tableName', function(req, res) {
Solution
Your callback should take in req
and res
, but is currently only taking in req
as res
.
app.post('/:tableName', function(req, res){
should give the function what it expects.