Node.js 具有express的节点中的访问请求参数

Node.js 具有express的节点中的访问请求参数,node.js,express,Node.js,Express,我在node express中有一些路线,如下所示 我需要通过路由器功能(get、post…)访问请求参数,以便使用用户的文件夹帐户设置常量。 这是代码段中的行: const uploadPath = path.join(__dirname, "../..", `public/${req.data.account_id}/uploads/clientes`); 可能吗 //app.js .... app.use('products',productRoutes) //pr

我在node express中有一些路线,如下所示

我需要通过路由器功能(get、post…)访问请求参数,以便使用用户的文件夹帐户设置常量。 这是代码段中的行:

const uploadPath = path.join(__dirname, "../..", `public/${req.data.account_id}/uploads/clientes`);
可能吗

//app.js
....
app.use('products',productRoutes)

//productRoutes
const express = require("express");
const router = express.Router();
const path = require("path");
//here I need access req params
const uploadPath = path.join(__dirname, "../..", `public/${req.data.account_id}/uploads/clientes`);

router.get('/list',(req,res)=>{
  console.log(uploadPath);
  ....
  ....
}

您可以创建一个函数,该函数接受请求对象的参数,然后生成并返回路径:

app.use('products',productRoutes)

//productRoutes
const express = require("express");
const router = express.Router();
const path = require("path");
//here I need access req params


function createPath(reqObj) {
   return path.join(__dirname, "../..", `public/${reqObj.data.account_id}/uploads/clientes`);
}
router.get('/list',(req,res)=>{
  const neededPath = createPath(req);
  console.log(neededPath);
  ....
  ....
}

上传路径的目的是什么?你想用它来回应吗?@路易扎夫斯,你有没有运气??