preface

A few years ago, when open source a Node.js project, I needed to configure some parameters such as qiuniuyunkey and wechat AppID. These parameters are required for development, but after submitting to GitHub, I hope these parameters are exposed. I have been submitting the code to it before deleting it (stupid method haha). Today I found a better way to deal with Tencent cloud OSS object storage SDK.

process

The process.env attribute returns an object containing the user’s environment. In the project, we can hide some important parameters by setting the system environment variables and use process.env to read (as shown in the figure above).

Windows

  1. WindowsIn the environment, we set environment variables through the visual operation interface

  1. throughNode.js process.envCommand line attempt to read

Linux

  1. In order toCentOS7.9For example, modifyvim /etc/profilefile
  2. File interface InputiThe file is appended after being editedexport Secretkey=keytypeshift+;, typewq!Save exit file

  1. typesource /etc/profileMake the configuration file take effect
  2. throughNode.js process.envCommand line attempt to read

conclusion

If you think this article is helpful to you, please like, comment and forward. First published in the finch documentation @is_tao