-3

I want to separate my route file in nodejs. I use restify framework and this is part of my code:

app.routes((app)=>{
  require(__dirname + '/../routes/web.js')
})

routes/web.js:

app.get('/', function (req, res, next) {
    console.log("object");
})

When run the program I get this error:

app is not a defined

How can I fix that?

In web.js app is undefined while I sended it to function.

Karol Selak
  • 4,248
  • 6
  • 35
  • 65

1 Answers1

0

in main file

require(__dirname + '/../routes/web.js')(app)

routes/web.js:

module.exports = function(app){
    app.get('/', function (req, res, next) {
        res.send("object");
    });
};