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

169
Views
Can't reach env from React Component in Next.js

I have a Next.js project. I have created .env file and using enviroments from this file in server.js file. But when I want to reach these enviroments from component, I can't access. What should I do?

This is .env file:

SERVER_PORT=3000
DOMAIN=127.0.0.1
DATABASE=dburl

This is server.js file:

require('dotenv/config')

const port = process.env.SERVER_PORT || 3000
server.listen(port, (err) => {
      if(err) throw err
      console.log(`Server listen on http://127.0.0.1:${port}`)
    })

This is any component of react:

axios
    .get(`http://${process.env.DOMAIN}/api/improve-language`)
    .then(res => {
      ...
    })
    .catch(err =>{
      console.log(err)
    })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Based on the documentation if you want to use the env variables in the browser, they must be named with prefix NEXT_PUBLIC_.

about 4 years ago · Juan Pablo Isaza Report
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!