Error: secretOrPrivateKey must have a value

It looks like your application can’t read the environment variable properly.

I don’t know which package you are using to load environment variables but the simplest way is using dotenv package.

After installing it with npm i dotenv, import it as early as possible in your application main file like this:

require("dotenv").config();

Create .env file in your application root folder with this content ( as you see the format is key=value)

MYSQL=jllgshllWEUJHGHYJkjsfjds90
JWT_KEY=secret

Then you can access their values like you already did:

process.env.JWT_KEY

.env file:

enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)