-2

Yes this question was asked before but I couldnt find any solution for me. So Ive just bought a new VPS (Ubuntu 14.04) to develope on since I dont want to work on my Main VPS anymore.
Ive copy pasted every file from my Main VPS (where everything is working) to my new VPS, installed everything and now wanted to start my nodejs app.

However Im getting the following error:

async function helpme()
      ^^^^^^^^

SyntaxError: Unexpected token function

My code:

var async = require('async');
async function helpme()
{
     console.log('Thanks for helping!');
}

The helpme() function is obviously just a test function so I dont need to copy paste and show you my full function where Im facing the same problem. Basically, this error happens everywhere Im using async, so it somehow needs to be broke but I have no idea.

Ive already installed async multiple times (npm async) but I cant find a way to fix it.

Any idea why that error is happening?

Thanks in advance!

bitifet
  • 3,514
  • 15
  • 37
Lukeyyy
  • 25
  • 3
  • 3
    what is your node js version ? async need a version that support *ES6*, i have no idea what `async` lib does but have you tried to change the variableName ? – Basil Battikhi Jul 24 '18 at 15:51
  • 3
    Also, the syntax for the async module (`require('async')`) is different from that of `async/await`. Which are you trying to use? See https://www.npmjs.com/package/async – c2huc2hu Jul 24 '18 at 15:53
  • @user3080953, No it should be okay like this, async function is used to replace the complexity of promises and callbacks – Basil Battikhi Jul 24 '18 at 15:56
  • 1
    @Basil I realize that, but why is OP calling `require('async')` to get async? It's a language feature, not a library – c2huc2hu Jul 24 '18 at 15:58

1 Answers1

0

async..await support was added in Node 7.6. The error means that currently used Node version is lower.

It doesn't make much sense to use both async library and async..await promise-based control flow simultaneously, but the fact that the variable is called async doesn't contribute to the problem. async is not a reserved keyword because the identifier with same name doesn't intervene with async function syntax.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565