Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

376
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda