Reputation: 1300
I have some environmental variables in my Node.JS .env, including AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET.
I added auth0 support to the client with:
var jwt = require('express-jwt');
var authenticate = jwt({
secret: new Buffer(process.env.AUTH0_CLIENT_SECRET, 'base64'),
audience: process.env.AUTH0_CLIENT_ID
});
When run my experiment either using $node experiment.js or as from npm [after adding a corresponding entry to scripts in package.json, I get an error:
buffer.js:139
throw new TypeError('must start with number, buffer, array or string');
My guess is that environmental variables are not being picked-up. What did I do wrong, or/and what should I check for?
Upvotes: 2
Views: 6958
Reputation: 7520
The fact that you put those inside a file doesn't mean they get loaded. You need to pass them to NodeJS. Either use some of the packages for managing config files and environmental variables (nconf, dotenv), or directly pass it when running the service (which is better as the secrets should not be saved in any kind of files for security reasons). If you chose the second it pretty much depends on the system you're running. If you using Windows, you should first set the environmental variable (in cmd):
set AUTH0_CLIENT_SECRET=test
node app.js
On Unix based systems you can directly pass it:
AUTH0_CLIENT_SECRET=test node app.js
Hope that helps :)
Upvotes: 2