node.js - Node environment variable not being read as string in app -
i'm using library requires secret string. i've set node variable so:
export jwt_secret=e177920e88165bd0090b1c6b544cf7
however, when try use in app, so:
const jwt = require('jsonwebtoken'); function usertoken(user) { return jwt.sign({ user: user.id, }, process.env.jwt_secret); }
it hits error says secret must string or buffer. thought node variables strings, not sure issue is. thanks.
hmm, works fine me. maybe try adding console.log(process.env.jwt_secret)
check env var being loaded correctly.
as side note, consider using kind of environment variable management library such dotenv. allows store of environment variables in .env
file like:
jwt_secret="abc" other_env_var="def"
it makes easier keep track of env vars :)
Comments
Post a Comment