How can I import the config file properly?

Viewed 730

I'm studying import/export and modules. I was able to import the jQuery file, but am getting an error when trying to import the config file.

This is the error i'm getting:

config:1
Failed to load resource: the server responded with a status of 404 (Not Found)

(I want to use a config file, because it will help me manage api tokens for dev and production.)

I'm trying to import the config file to the jquery file:

Here is the content in the config file:

export default {
    WEATHER_API_ENDPOINT: `https://api.weatherbit.io/v2.0/forecast/daily?`,
    API_KEY: process.env.API_KEY,
  }

Here is part of the jquery file:

import config from './config'

let weatherBaseUrl = config.WEATHER_API_ENDPOINT;
let weatherApiKey = config.API_KEY;

...

export default function handleJquery() {
    $(handleExploreApp);
}

Here is the content in the main file:

import handleJquery from './jquery.js'

handleJquery()

the main file is linked to in the html file like so:

  <script type="module" src="main.js"></script>

Here is a link to the repo

(Would webpack help for this?)

1 Answers

try this

const Config = {
    WEATHER_API_ENDPOINT: `https://api.weatherbit.io/v2.0/forecast/daily?`,
    API_KEY: process.env.API_KEY,
  } 
export default Config

Related