gpt4 book ai didi

node.js - 当我尝试将其部署到 Nodejs v8.11.4 上的 aws 云时,"SyntaxError: Unexpected identifier"异步等待

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:57 25 4
gpt4 key购买 nike

我尝试使用 async wait 将我的项目部署到 aws,实际上它在本地运行,但是当我永远使用 npm 启动它时,我收到了错误

    async getStock(req, res) {
^^^^^^^^

SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (rcenter.id/task/routes/stock.js:3:22)
error: Forever detected script exited with code: 1

这里是我的 stock.js

module.exports = {

async getStock(req, res) {

try {
let body = req.body;
let limit = parseInt(req.body.limit);
let offset = 0;

let stocks = await Stock.findAndCountAll({});

let page = req.body.page;

let pages = Math.ceil(stocks.count / limit)
offset = limit * (page - 1)


let stock = await Stock.findAll({
limit: limit,
offset: offset,

});

//count json data per page
let key, count = 0;
for (key in stock) {
if (stock.hasOwnProperty(key)) {
count++;
}
}
console.log(count)
res.send({ "http_code": 200, "status": "success", "code": "SSR001", "message": "get data success", "data": stock,"current_page": page, "total_pages": pages,"maximum_record":limit, "total_records":count })

} catch (err) {
console.log(err);
return res.status(500).json({"http_code": 500, "status": "failed", "code": "SON004","message":"data not found" })
}
}

}

我的 stock.js 有什么问题吗?

注意:我使用的是node-v8.11.4,我也永远使用npm来运行脚本

最佳答案

您的模块的语法错误。您已在 module.exports 对象中放置了一个函数,但尚未将该函数分配给属性。

您的代码结构应如下所示:

module.exports = {
getStock: async function getStock() {...}
};

关于node.js - 当我尝试将其部署到 Nodejs v8.11.4 上的 aws 云时,"SyntaxError: Unexpected identifier"异步等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52296230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com