node.js - 异步/等待未在 Azure 应用服务中运行

标签 node.js azure asynchronous backend

在我的 Azure 应用服务 Node.js 后端中,我似乎无法运行 Javascript 异步/等待功能。我有changed the default version of Node.js在应用程序设置和 package.json 中高于 7.6。 (改为8.9.0)

我想在此处所示的自定义 Express 路由器中使用此功能:

var express = require('express'),
    bodyParser = require('body-parser');

var router = express.Router();

router.get('/', function (req, res, next) {
    res.status(200).send('GET: This is a test response!');
});

router.post('/:id', async function (req, res, next) { 
    var context = req.azureMobile;

    var newLovedOne = req.body.lovedone;        
    var newTie = req.body.tie;

    console.log('POST: newLovedOne ', newLovedOne);
    console.log('POST: newTie ', newTie);

    try {
        await context.tables('Tie').insert(newTie);
        await context.tables('LovedOne').insert(newLovedOne);
    } catch (error) {
        res.status(500).send('Insert failed!');
    }

});

module.exports = router;

尝试使用上述路由器启动应用程序会产生以下结果:

Application has thrown an uncaught exception and is terminated:
SyntaxError: missing ) after argument list
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\home\site\wwwroot\app.js:12:20)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

最佳答案

要验证 Node.js 版本是否设置正确,您可以转到根目录并打开 iisnode.yml 文件。确保以下行具有正确的版本:

nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.9.0\node.exe"

关于node.js - 异步/等待未在 Azure 应用服务中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49259536/

相关文章:

node.js - NodeJS/express - 公共(public) API 端点的安全性

c++ - 5_4-2016q3\bin\arm-none-eabi-g++ 未找到 - Windows 10

c# - Azure Functions 和 Azure Durable Function 之间有什么区别

objective-c - 如何让 MainThread 等到某些异步操作完成?

c# - 如何在不运行异步方法的情况下对异步方法的任务结果进行排队?

java - 页面更改时更改 fragment 内容,ViewPager

arrays - 为什么制作更小的阵列需要更长的时间?

javascript - 如何在sequelize中获取多对多关系的中间表的数据

node.js - 如何根据环境更改 Meanapp 或 Nodejs 应用程序中的基本 Url?

azure - 不支持 HDInsight 区域。区域代码 : ln