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
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
Thank you @annadema, Youâre a life saver!
Thank you for your feedback
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
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â