如何将参数从 express 传递给普通的 const 变量?
How to pass parameter from express to normal const variable?
我有一个 express
POST 路由器,它将数据发送到我的其他 NodeJS 脚本。
比如我发过来username, password
这是我要将这些参数发送到的脚本
const options = {
cookiesPath: './cookies.json',
username: {I want to send username here},
password: {I want to send password here},
userslist: null,
dryrun: false,
}
此 options
文件稍后在另一个 async
函数内的代码中被
再次调用
const doWork = async (users = []) => {
usersToBeUsed = users;
const instauto = await Example(browser, options);
}
如何在我的 const options
中捕获这些参数?
我想您发送的表单包含两个名为用户名和密码的输入及其值。您的路线将如下所示:
router.post("/my/path", controller.myFunction);
那么你的函数应该看起来像这样:
exports.myFunction = (req, res) => {
console.log(req.body); //See how your data looks like
const options = {
cookiesPath: './cookies.json',
username: req.body.username,
password: req.body.password,
userslist: null,
dryrun: false,
};
//do something with the data and send the response, render, etc...
};
我有一个 express
POST 路由器,它将数据发送到我的其他 NodeJS 脚本。
比如我发过来username, password
这是我要将这些参数发送到的脚本
const options = {
cookiesPath: './cookies.json',
username: {I want to send username here},
password: {I want to send password here},
userslist: null,
dryrun: false,
}
此 options
文件稍后在另一个 async
函数内的代码中被
const doWork = async (users = []) => {
usersToBeUsed = users;
const instauto = await Example(browser, options);
}
如何在我的 const options
中捕获这些参数?
我想您发送的表单包含两个名为用户名和密码的输入及其值。您的路线将如下所示:
router.post("/my/path", controller.myFunction);
那么你的函数应该看起来像这样:
exports.myFunction = (req, res) => {
console.log(req.body); //See how your data looks like
const options = {
cookiesPath: './cookies.json',
username: req.body.username,
password: req.body.password,
userslist: null,
dryrun: false,
};
//do something with the data and send the response, render, etc...
};