简体   繁体   English

通过FTP部署nodejs时如何隐藏我的密码

[英]How to hide my password when deploying nodejs through FTP

How to hide my password when deploying nodejs through FTP?通过FTP部署nodejs时如何隐藏我的密码? It seems the following code will be seen by everyone in GitHub repository.似乎下面的代码会被 GitHub 存储库中的每个人看到。 Also, when people download my file, they can also see the password.此外,当人们下载我的文件时,他们也可以看到密码。 How to avoid this problem?如何避免这个问题? Thank you very much!非常感谢!

const Client = require('ftp');
const connectionProperties = {
      host: 'ftp.example.com',
      user: '',
      password: '12345678'

Use dotenv to retreive all environment variables from .env file.使用dotenv.env文件中检索所有环境变量。

Installation安装

npm install dotenv

In your .env file.在您的 .env 文件中。

HOST=ftp.example.com
PASSWORD=12345678

In your script file在你的脚本文件中

const dotenv = require('dotenv')
dotenv.config()

const Client = require('ftp');
const connectionProperties = {
      host: process.env.HOST,
      user: '',
      password: process.env.PASSWORD


Please note that you should edit .gitignore file ignore .env file from the git source control.请注意,您应该编辑.gitignore文件,忽略来自 git 源代码管理的.env文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM