0

I'm trying to use the mlb-stats-api in NodeJS but am running into this issue. Whenever I run the script in runkit it runs completely fine but whenever I try to run it in my terminal I get this error:

 SyntaxError: await is only valid in async functions and the top level bodies of modules

Here is the script I am trying to run based off of the documentation:

const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

const response = await mlbStats.getDivisions();
  • 1
    You are not in an ESM module where `await` is allowed at the top level. You are in a CommonJS module where await is not allowed at the top level. – jfriend00 Apr 24 '22 at 21:05

0 Answers0