Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS dotenv - Not reading string value properly

Tags:

I'm trying to us dotenv (https://github.com/motdotla/dotenv) in nodeJS to store the client secret value for an oauth server I'm using.

My .env file looks like the following:

clientSecret=imU86A3oPiZlyOhZybShraP377ers0MvowBaizEQ

Within the NodeJS file, I have the following:

passport.use(new PasswordGrantStrategy({
    tokenURL: 'WEBSITE_ADDRESS',
    clientID: "2",
    clientSecret: process.env.clientSecret,
    grantType: "password",

},

The problem is that I get a Token Error but, if I change it the following:

passport.use(new PasswordGrantStrategy({
    tokenURL: 'WEBSITE_ADDRESS',
    clientID: "2",
    clientSecret: "imU86A3oPiZlyOhZybShraP377ers0MvowBaizEQ",
    grantType: "password",

},

This then works perfectly fine. I don't understand what the problem could be and I've tried to cast it as a string but no such luck.

The values are both matching and I'm printing them out and they are both the same.

like image 843
Phorce Avatar asked Mar 13 '17 11:03

Phorce


1 Answers

Use a backtick to wrap the string value and your life will be a breeze!

clientSecret=`imU86A3oPiZlyOhZybShraP377ers0MvowBaizEQ`
like image 189
jsdecena Avatar answered Sep 25 '22 11:09

jsdecena