Error: .post () requires callback functions, but has [Undefined object]

I am new to host / express and I keep getting this exception.

Error: .post () requires a callback function, but received [Undefined object]

with this code

nu = require('./routes/create_newissue.js');
app.post('/create_newissue',nu.resources); 

The code in exports.create_newissueworks fine if I put it in app.js. However, if I put it in a separate file, .jsit will give the above error.

+8
source share
3 answers

You should have something like this in create_newissue.js

exports.resources = function(req, res){
   // Your code...
}
+14
source

The error received indicates that nu.resources sent to app.post ( ) is not a function.

, , ...

, :

app.js: app.js :

 require('./routes')(app);

, app.js routes.js

routes.js

var nu = require('./path/nu');
module.exports = function (app) {
          app.post('/create_newissue',nu.resourcesFunc);
    };

nu.js

exports.resourcesFunc = function (req, res) {
    //TODO: do your stuff here...
};

, , (req, res) {...} app.post(), :

app.post('/address',function (req, res) {...});
+3

. . nu = require ('.//create_newissue.js')();

0

Source: https://habr.com/ru/post/1535597/


All Articles