簡體   English   中英

通過FTP部署nodejs時如何隱藏我的密碼

[英]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

在您的 .env 文件中。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM