天道酬勤,学无止境

shrinkroute

如何将变量从app.js传递到route / index.js?(How to pass variable from app.js to routes/index.js?)

问题 我正在使用收缩路线https://npmjs.org/package/shrinkroute在nodejs中建立链接。 我收到错误500 ReferenceError:收缩器未定义 如何将rinkeroute传递给routes / index.js? 有没有更好的方法通过传递查询字符串args创建url? //app.js var app = express(); var shrinkr = shrinkroute( app, { "user": { path: "/user/:id?", get: routes.showOrListUsers } }); //url method works in app.js var url = shrinkr.url( "user", { id: 5, page:40, type:'a' } ); console.log(url); app.use( shrinkr.middleware ); //routes/index.js exports.showOrListUsers = function(req, res, next) { console.log(req.params); //shrinkr errors out in index.js var url2 = shrinkr.url( "users", {name: "foo"

2021-04-29 15:54:27    分类:技术分享    node.js   express   shrinkroute

How to pass variable from app.js to routes/index.js?

I'm using shrinkroute https://npmjs.org/package/shrinkroute to make links in nodejs. I get error 500 ReferenceError: shrinkr is not defined How to pass shrinkroute to routes/index.js? Is there a better way to create url by passing query string args? //app.js var app = express(); var shrinkr = shrinkroute( app, { "user": { path: "/user/:id?", get: routes.showOrListUsers } }); //url method works in app.js var url = shrinkr.url( "user", { id: 5, page:40, type:'a' } ); console.log(url); app.use( shrinkr.middleware ); //routes/index.js exports.showOrListUsers = function(req, res, next) { console

2021-04-16 01:20:15    分类:问答    node.js   express   shrinkroute