user12219356
user12219356

Reputation:

Getting Error when adding an async function on NodeJS

I am trying to add async method on node.js v6.11 but i, getting Unexpected identifier error.

let fs = require('fs');
let Config = require('../somefolders/config.js');

module.exports = class SomeClassName {
  constructor(id = null) {

  }

  //Some other methods

  static async test1234(param) {

  }

  //Some other Static methods
}

This is the error We are getting:

Error

Upvotes: 2

Views: 151

Answers (2)

Kuldeep Singh
Kuldeep Singh

Reputation: 11

use Node version 7.6 or above. async/await added in ES2017.

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1075039

The error in the screenshot tells us you're using an old version of Node.js that doesn't have async/await support. Node.js has had async/await for years, but if I go back to v7, I can replicate exactly the error in your screenshot.

If you update to an up-to-date version of Node.js (or even a vaguely-recent one), that code is just fine.

Upvotes: 2

Related Questions