如何在Heroku上启用ES2017function来运行Node.js应用程序?

我是新来的节点,并创build了一个应用程序,它有一些async / await语法就像这样:

const express = require('express'); const app = express(); const someLibrary = require('someLibrary'); function asyncWrap(fn) { return (req, res, next) => { fn(req, res, next).catch(next); }; }; app.post('/getBlock', asyncWrap(async (req,res,next) => { let block = await someLibrary.getBlock(req.body.id); [some more code] })); app.listen(process.env.PORT || 8000); 

它在我的机器上工作正常,但是当我部署到Heroku我得到一个错误,因为语法不支持:

 2017-03-23T10:11:13.953797+00:00 app[web.1]: app.post('/getBlock', asyncWrap(async (req,res,next) => { 2017-03-23T10:11:13.953799+00:00 app[web.1]: SyntaxError: Unexpected token ( 

让Heroku支持这个语法最简单的方法是什么?

指定要在package.json中使用的节点版本: https : //devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

所以对于asynchronous/等待支持,你需要指定> = 7.6.0

 { "engines": { "node": ">= 7.6.0" } } 

从这里的Heroku文档

https://devcenter.heroku.com/articles/getting-started-with-nodejs#declare-app-dependencies

应该在你的package.json文件中声明哪些引擎应该是可访问的:

 { "name": "node-js-getting-started", "version": "0.2.5", ... "engines": { "node": "5.9.1" }, "dependencies": { "ejs": "2.4.1", "express": "4.13.3" }, ... }