I have a password. I don't want to commit it to the repo. I am writing tests with puppeteer. The logical thing to do would be to save the password in a file somewhere, git-ignore the file, then load it in puppeteer. But I'm not sure how to do that. Suggestions?
This is what I am trying. It doesn't work, yet:
file loadPassword.js:
import { config } from "dotenv"; // This appears in lightweight type in VS code, implying that VS code thinks the line is not doing anything.
console.log('getting password');
let pass = process.env.PASSWORD;
console.log('the actual password has been loaded into the variable "pass".');
console.log('the password is ', pass);
let foo = process.env['PASSWORD'];
console.log(foo);
// but when I run, both pass and foo print out as undefined.
file .env:
{
PASSWORD: 'secret'
}
file package.json:
{
"type": "module",
"dependencies": {
"dotenv": "^16.0.3",
"puppeteer": "^19.8.3"
}
}
To run, in terminal:
node loadPassword