Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

413
Vistas
Trying to use AXIOS for get request, error "require is not defined"

My code is below. This is my first time using NodeJS and axios.

I have installed NodeJS on Windows using the downloadable installer. I then installed Axios using npm install axios in powershell as admin.

I'm obviously copy/pasting the boilerplate nodejs code for an axios get request.

I've tested the php file using a curl get request from command line (installed actual curl, not the windows shortcut to another program.) So the PHP is accepting get requests and serving json back properly.

The issue I'm stuck on is how to setup axios and node js properly so that my js file runs the get request properly.

This is my code

const loginForm = document.getElementById("login-form");
const loginButton = document.getElementById("login-form-submit");
const loginErrorMsg = document.getElementById("login-error-msg");
const vanillaUrl = "localhost:8081/hospital/php/addapt.php";
const getUrl = "localhost:8081/hospital/php/getpatientappt.php?PatientID=1";

const axios = require('axios')
//get request to get appt for patient id1
axios
    .get(geturl)
    .then(res => {
        console.log(`statusCode: ${res.status}`)
        console.log(res)
        alert(res)
    })
    .catch(error => {
        console.error(error)
    })


loginButton.addEventListener("click", (e) => {
    e.preventDefault();
    const username = loginForm.username.value;
    const password = loginForm.password.value;
    if (username === "user" && password === "1") {
        alert("You logged in!");
        location.reload();
    } else {
        loginErrorMsg.style.opacity = 1;
    }
}
)

These are the errors I'm getting in chrome from the javascript console

Uncaught ReferenceError: require is not defined
    at login-page.js:7:15

DevTools failed to load source map: Could not load content for chrome-extension://hnfanknocfeofbddgcijnmhnfnkdnaad/content.js.map: System error: net::ERR_BLOCKED_BY_CLIENT

DevTools failed to load source map: Could not load content for http://localhost:8081/hospital/login/requestProvider.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

When I run incognito I get

Uncaught ReferenceError: require is not defined
    at login-page.js:7:15

there is no file requestProvider.js.map or content.js.map

This is all being hosted on localhost with xampp. I'm not sure if that affects anything.

I'm not sure what this error is. Got stuck googling it. And I'm not sure how to integrate this code properly.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

seems like you're running this code in browser, browser implementation of Javascript doesn't have require function

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda