简体   繁体   中英

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;
    }
  };

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;
      }
    };

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM