Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables in NodeJs using cPanel

So I'm using cPanel with Setup Node.js App plugin for a Next.js app. (don't asky why cPanel)

Everything is working as expected in development, except for environment variables in production, I set up them manually from the cPanel interface, I restarted/stopped the app, logging the process.env on the server and I don't see the env variables there (not to say when trying to call them they are undefined).

When doing res.json(JSON.stringify(process.env)); i get a bunch of variables except for the one I manually wrote in cPanel variables interface.

It is important for me to store these variables as secret key because they are API credentials.

Anyone know what I might have misconfigured or had this problem?

like image 302
Paul Şular Avatar asked Apr 27 '26 09:04

Paul Şular


1 Answers

Never mind, found the answer, apparenlty was a Next.js misconfiguration. I had to add the following lines of code inside next.config.js in order to read env variables on build version.

require('dotenv').config();

module.exports = {
  env: {
    EMAIL_NAME: process.env.EMAIL_NAME,
    EMAIL_PASSWORD: process.env.EMAIL_PASSWORD,
    GETRESPONSE_API_KEY: process.env.GETRESPONSE_API_KEY
  }
};

Where EMAIL_NAME, EMAIL_PASSWORD, GETRESPONSE_API_KEY were the variables defined by me on cPanel interface

like image 83
Paul Şular Avatar answered Apr 28 '26 23:04

Paul Şular



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!