Error: secretOrPrivateKey must have a value

Remove the process.env.JWT_SECRET_KEY and do it this way: ${process.env.JWT_SECRET_KEY} wrap it with backtick. It solved the problem for me.


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