如何在没有错误的情况下包含js文件?
How to include js file with no error?
我想在 nodejs 中分离我的路由文件。我使用 restify 框架,这是我的代码的一部分:
app.routes((app)=>{
require(__dirname + '/../routes/web.js')
})
routes/web.js:
app.get('/', function (req, res, next) {
console.log("object");
})
当 运行 程序出现此错误时:
app is not a defined
我该如何解决?
在 web.js 中 app
是 undefined
而我将其发送到函数中。
在主文件中
require(__dirname + '/../routes/web.js')(app)
routes/web.js:
module.exports = function(app){
app.get('/', function (req, res, next) {
res.send("object");
});
};
我想在 nodejs 中分离我的路由文件。我使用 restify 框架,这是我的代码的一部分:
app.routes((app)=>{
require(__dirname + '/../routes/web.js')
})
routes/web.js:
app.get('/', function (req, res, next) {
console.log("object");
})
当 运行 程序出现此错误时:
app is not a defined
我该如何解决?
在 web.js 中 app
是 undefined
而我将其发送到函数中。
在主文件中
require(__dirname + '/../routes/web.js')(app)
routes/web.js:
module.exports = function(app){
app.get('/', function (req, res, next) {
res.send("object");
});
};