"Process is not defined" during use Ajax with API

98 views Asked by At

I have problem because I an error "Uncaught ReferenceError: process is not defined". I want add my API_KEY to the folder .env but I can not do this. My code looks like: (this is index.js)

$(document).ready(function() {
  $("#textButton").click(function() {
    var APIkey = process.env.API_KEY; //here I want add my hiding API to variables API_KEY which is in folder .env
    const approvalText = $("#textCity").val();
    if (approvalText != '') {
      $.ajax({
        type: 'GET',
        url: 'https://api.openweathermap.org/data/2.5/weather?q=' + approvalText + "&appid=" + APIkey + '&units=metric',
        dataType: "json",
        success: function(data) {
          $(".city_name").html(data.name + ', ' + data.sys.country);
        }
      });
    } else {
      alert("Please write city name on text field");
    }
  });
});

My structure of folders and subfolders

enter image description here

I have installed: -node v12.18.4 -npm 6.14.6 and dotenv

How I can resolve my problem?

0

There are 0 answers