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

386
Vistas
reactjs .env add localhost:3000 to my axios path

I am working on a react app

I am using axios for api request

I added my base url in .env

when I submitted my form and I checked the network tab

I saw this

http://localhost:3000/%22http://localhost:8000/api/%22;get-name

instead of this

localhost:8000/api/get-name

.env

REACT_APP_DEV_BASE_URL = "http://localhost:8000/api/";

my code

import React from "react"
import axios from "axios";
const Home = () => {

 const getName = () => {

 axios.get(`${process.env.REACT_APP_DEV_BASE_URL}get-name`, {"name": "John Stone"})
      .then((respons) => {})
      .catch((error) => {})
      .finally(() => {
        console.log("finished...");
      });
  }
  return (
     <div><button onClick={getName}>Get Name</button>
  )
}

export default Home
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to declare your environment variables very carefully. Don't use semicolon or comma at the end of the line. Also you don't have to put single or double quotes to wrap up your values(if you add it will work but this is not the right way of declaring your .env variables). So change your .env file in this way:

REACT_APP_DEV_BASE_URL=http://localhost:8000/api/

Finally restart your dev server.

For more information, read this docs out.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In order to make use of environment variables living in the .env file, you ought to add the following code to your project's entry file, it is often App.js:

import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:8000/api';
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