Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将参数传递给Express route/module_Javascript_Node.js_Express - Fatal编程技术网

Javascript 将参数传递给Express route/module

Javascript 将参数传递给Express route/module,javascript,node.js,express,Javascript,Node.js,Express,我有一个Express server,它创建了一个WSS服务器,如下所示: const WebSocket = require('ws'); const wss = new WebSocket.Server({ port: '8080' }); wss.on('connection', async (ws, req) => { ... }) // routes setup const chatRouter = require('./routes/chatPoint')(wss);

我有一个Express server,它创建了一个WSS服务器,如下所示:

const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: '8080' });

wss.on('connection', async (ws, req) => { 
 ...
})

// routes setup
const chatRouter = require('./routes/chatPoint')(wss);

app.use('/api/chat', chatRouter);
我正在尝试将参数“wss”传递给以下模块:

router.patch('/title', jsonParser, async (req, res) => {
   ...
});

module.exports = router;
我当前遇到的错误是:

    return fn.apply(this, arguments);
              ^
TypeError: Cannot read property 'apply' of undefined

请提供建议。

使用。设置属性,您可以从任何中间件通过
请求
对象访问它,作为
请求应用程序局部变量

使用。设置属性,您可以从
请求
对象访问它,作为
请求应用程序局部变量
从任何中间件访问。

我将如何传递或只是访问模块中的ss app.locals.wss?@PetarIvcec
app.locals.wss=wss
。我已经尝试过了:
router.patch('/title',jsonParser,async(req,res)=>{console.log('wss',app.locals.wss);…
给了我“app not defined”
console.log('req.app.locals.wss',req.app.locals.wss);
允许我访问路由模块内的wss。谢谢:)我如何传递或仅访问模块内的app.locals.wss?@PetarIvcec
app.locals.wss=wss
。我已经尝试过了,但正在做:
路由器.patch('/title',jsonParser,async(req,res)=>{console.log('wss',app.locals.wss);…
给我的应用程序未定义“
console.log('req.app.locals.wss',req.app.locals.wss);
允许我访问路由模块内的wss。谢谢:)