https://github.com/node-config/node-config
Quote from github:
Install in your app diectory, and edit the default config file:
$ npm install config
$ mkdir config
$ vi config/default.json"
here the overview talks about how to install it and THEN creating the dir config. but after installing via 'npm install config' there already was a folder "node_modules/config" created. how could it be installed without that folder anyhow and why do I need to create a foulder AFTER the instalation??
more important question: these files do not exist:
- config/default.json
- config/production.json
and somehow my node.js server isn't taking my post request correctly and the debugger stops here:
M:...\Projekt22\node_modules\config\lib\config.js:182
throw new Error('Configuration property "' + property + '" is not defined'); ^
Error: Configuration property "sessionStorage.timeout" is not defined
So I wonder now, if there is an issue with my config.js, with the "config/default.json" or "config/production.json"... that don't exist...
Can anyone explain all this to me?
This are the lines, where my code stops working:
var expirationTime = config.get("sessionStorage.timeout")
var expiresAT = issueAt + (expirationTime * 1000)
And this is the whole module of my program, where the crash happens:
var userService = require("../user/UserService")
var jwt = require("jsonwebtoken")
var config = require("config")
/* const logger = require("nodemon/lib/utils/log"); */
function createSessionToken(props, callback) {
console.log("AuthenticationService: create Token");
if (!props) {
console.log("Error: have no json body")
callback("JSON-Body missing", null, null)
return
}
userService.findUserBy(props.userID, function (error, user) {
if (user) {
console.log("Found user, checking password...")
user.comparePassword(props.password, function (err, isMatch) {
if (err) {
console.log("Password is invalid")
callback(err, null);
}
else {
console.log("Password is correct. Create token.")
var issueAt = new Date().getTime()
var expirationTime = config.get("sessionStorage.timeout")
var expiresAT = issueAt + (expirationTime * 1000)
var privateKey = config.get("session.tokenKey")
let token = jwt.sign({ "user": user.userID }, privateKey, { expiresIn: expiresAT, algorithm: "HS256" })
console.log("Token created: " + token)
callback(null, token, user)
}
}
)
}
else {
console.log("Session Services: Did not find user for user ID: " + props.userID)
callback("Did not find user", null);
}
})
}
module.exports = {
createSessionToken
}
Where is the problem?