bumblebee
bumblebee

Reputation: 21

SyntaxError: Unexpected token

a simple method is throwing me syntax error:

SyntaxError: Unexpected token .

module.exports.verifyStandardMetadata(data) => {
  const result;
  const json = JSON.parse(data);
    if (json.status === '') {
      json.status = 'Draft';
      result = JSON.stringify(json);
      return result;
    }
  };

Upvotes: 2

Views: 161

Answers (2)

James
James

Reputation: 82096

Your export syntax is wrong - module.exports.verifyStandardMetadata(...) would attempt to call a function, you want to set the function i.e.

module.exports.verifyStandardMetadata = data => {
  ....
}

Upvotes: 0

libik
libik

Reputation: 23029

the syntax must be a little different

module.exports.verifyStandardMetadata = (data) => {
    const result;
    const json = JSON.parse(data);
      if (json.status === '') {
        json.status = 'Draft';
        result = JSON.stringify(json);
        return result;
      }
    };

Also you have to change the result from const to let as you are changing it

module.exports.verifyStandardMetadata = (data) => {
    let result;
    const json = JSON.parse(data);
      if (json.status === '') {
        json.status = 'Draft';
        result = JSON.stringify(json);
        return result;
      }
    };

Upvotes: 1

Related Questions