[英]How to hide my password when deploying nodejs through FTP
通過FTP部署nodejs時如何隱藏我的密碼? 似乎下面的代碼會被 GitHub 存儲庫中的每個人看到。 此外,當人們下載我的文件時,他們也可以看到密碼。 如何避免這個問題? 非常感謝!
const Client = require('ftp');
const connectionProperties = {
host: 'ftp.example.com',
user: '',
password: '12345678'
使用dotenv從.env
文件中檢索所有環境變量。
npm install dotenv
HOST=ftp.example.com
PASSWORD=12345678
const dotenv = require('dotenv')
dotenv.config()
const Client = require('ftp');
const connectionProperties = {
host: process.env.HOST,
user: '',
password: process.env.PASSWORD
請注意,您應該編輯
.gitignore
文件,忽略來自 git 源代碼管理的.env
文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.