I have set a variable that is shown below
pathImage = __dirname + '/bot.jpg;
I want to pass the value of pathImage
to IconUrl from my .env file. This is how I do it. var invite = new Welcome(process.env.IconUrl=pathImage, process.env.BotVersion);
Finally, I'm getting this error from NodeJs
[onTurnError]: SyntaxError: Unexpected token U in JSON at position 633
But, this works for me (setting path manually, not preferable way)
var invite = new Welcome(process.env.IconUrl='C:/Users/Mackhem/Desktop/testBot/bot.jpg', process.env.BotVersion)
I think there's a few things that are off:
'
in pathImage = __dirname + '/bot.jpg;
-- maybe just a typoprocess.env.IconUrl
, but you're setting it at the same time with process.env.IconUrl=pathImage
In your .env
file:
IconUrl=bot.jpg
In your other file:
const pathImage = path.join(__dirname, '..', process.env.IconUrl);
var invite = new Welcome(pathImage, process.env.BotVersion);
Note: You cannot use __dirname
in the .env
file since everything in the .env
file gets converted to a string.