Error: uncaughtException: FATAL ERROR:jwtPrivateKey is not defined

error: uncaughtException: FATAL ERROR:jwtPrivateKey is not defined

Hey, if you’re on windows, and you’ve been following Mosh’s codes, this might be the solution that you’re looking for. Open terminal (not integrated teminal in VS Code), and then set the jwtPrivateKey like this >>> set vidly_jwtPrivateKey=mySecureKey , and then run the application using >>>> node index.js

1 Like

If you want to know the reason for this:

Look at the video “10. Storing Secrets in Environment Variables” in section “Authentication and Authorization” of Node course. There Mr Mosh explain clearly all the steps to set the jwtPrivateKey in an environment variable.
In brief:
install config package, load it, create a folder config. create inside of it two files: default.json and custom-environment-variables.json.
then set the env.

Otherwise if you only want to have a quick solution to continue with your code
In the terminal tab run:
set vidly_jwtPrivatekey=MySecretKey
(Note: without any quotes)
Then in the same terminal tab (below the editor one) run:
nodemon index.js

If you still have the same error, check the value of the property jwtPrivateKey in the file
‘vidly\config\custom-environment-variables.json’. This is the environmental variable that you have to set in your terminal. Usually it should be vidly_jwtPrivatekey :slight_smile:

1 Like

Thank you @annadema, You’re a life saver!

1 Like

Thank you for your feedback :slight_smile:

1 Like

I have a problem in section 3,

“(node:11412) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(Use node --trace-deprecation ... to show where the warning was created)
Connected to MongoDB…
SyntaxError: Unexpected token S in JSON at position 11
at JSON.parse ()
at parse (C:\Users\SharelShalom\Desktop\COMPUTER\nodeCourse\vidly\node_modules\body-parser\lib\types\json.js:89:19)
at C:\Users\SharelShalom\Desktop\COMPUTER\nodeCourse\vidly\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\Users\SharelShalom\Desktop\COMPUTER\nodeCourse\vidly\node_modules\raw-body\index.js:224:16)
at done (C:\Users\SharelShalom\Desktop\COMPUTER\nodeCourse\vidly\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\Users\SharelShalom\Desktop\COMPUTER\nodeCourse\vidly\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)”

Are you know something avout this?

@ishakmohmed Thank you. Your solution worked for me

1 Like

Thank you!!
Verry clearly, it’s verry importent to know it.
You helped me.

here is the final solution :$env:vidly_jwtPrivateKey = “mySecureKey”
use this method for setting environment variables

use this $env:vidly_jwtPrivateKey = “mySecureKey”