简体   繁体   中英

Why am I getting Error: Configuration property “jwtPrivateKey” is not defined?

I keep getting this error message when I run my index.js file via NodeJS terminal. My editor is VS Code. I am on Windows.

I loaded npm config module into my index.js file. I created a custom-environment-variables.json. I set my password, vidlyPrivateKey, in my Node Terminal. I don't know why this is happening. Any help would be much appreciated!

Here is my index.js code:

const config = require('config');
try {
    const myKey = config.get("jwtPrivateKey");
    debug(myKey);
} catch (error) {
    debug(error, "FATAL ERROR: jwtPrivateKey is not defined.");
   return process.exit(1);
}

custom-environment-variables.json:

{
    "jwtPrivateKey": "vidlyPrivateKey"
}

It is because the naming of the file, it should be inside a config folder and be name as default.json , config/default.json

在此处输入图像描述

These are the documentation https://www.npmjs.com/package/config .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM