secretOrPrivateKey must have a value secretOrPrivateKey must have a value mongoose mongoose

secretOrPrivateKey must have a value


I think your calling of node is probably wrong. Try node server.js and you should get the default config. You can also put a console.log in the exports.get() to see what it is sending in as an environment variable.


I think you have a problem with your config. The only thing you export is a function get. so config.SECRET is empty. you should have write config.get().SECRET


In my case, I have this folder structure.

  • Project

    • frontend

    • backend

      • index.js
      • .env

I ran into the error "secretOrPrivateKey must have a value" because the terminal was in Project folder and I ran nodemon backend/index.js. I wasn't in the correct folder with .env file to run the backend. cd backend && nodemon index.js helps