Patrick Connors Patrick Connors - 2 years ago 136
Node.js Question

Async function not supported in NodeJS app deployed to Heroku

I'm trying to implement asynchronous functionality in one of my routes in a NodeJS app. It works when I run it on localhost but when deployed to heroku, an error

unexpected token (
is thrown in the first line of the following code:'/post', async(req,res) => {
const data = await getData();
//do stuff


I'm a little confused as to why this works in one environment and not the other. Are there heroku configurations I'm missing? Do I need to explicitly add support for ES2016/2017 in Heroku?

Answer Source

Heroku defaults to the latest Long Term Support version of Node (which, as of writing, is v6.11.1) if you don't set a specific version.

async/await has been available in Node since v7.6, so you'll need to explicitly specify at least that version in your package.json, as documented here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download