Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
How to set up my project to handle Axios/Fetch CRUD requests for Heroku

I'm quite new to Heroku and backend overall.. I'm trying to deploy an app to heroku which makes POST requests in the frontend to the backend server (MERN stack). Everything works fine ONLY on the localhost.

I tried setting the server link to "page_name.herokuapp.com" and even left the url empty with "/refresh" and "/" but it does not seem to recognize that I'm making POST requests.

I heard about environmental variables - but I'm not sure how to set them up. Do I make an env file and put the const baseUrl in there or should I do it on the settings in Heroku ?

Sorry if this is a silly mistake, but I cant figure out how to make my frontend/backend cooperate.

const baseUrl = process.env.baseURL || "http://localhost:3001";

useEffect(() => {
    fetch(`${baseUrl}/`)
    .then((res) => res.json())
    .then((res) => setStocks(res))
  },[]); 

const handleRefresh = (e) => {
  e.preventDefault();
  const res = e.target.dataset.value;

  if (stocks !== '') {

    const options = 
    {
      method: 'POST',
      headers: {
        'Content-Type':  'application/json'
      },
      body: JSON.stringify({res}),
    };

    const response = fetch(`${baseUrl}/refresh`, options);

  };
}

these are the package.json scripts file for react/frontend

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
  },

Procfile:

web:nodemon backend/index.js // tried node backend/index.js as well

https://github.com/szumi112/stockpricesapp - here's my github for more information

Not sure what else I can do to figure this out. Let me know if more information is needed.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!