how to config custom process.env in node.js
process.env
APP_ENV
NODE_ENV
https://nodejs.org/api/process.html#process_process_env
GITHUB_API_ACCESS_TOKEN
#!/usr/bin/env node
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-08-0
* @modified
*
* @description
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link https://www.cnblogs.com/xgqfrms/p/13500721.html#4658099
* @solutions
*
*/
const log = console.log;
log(`process.env =\n`, process.env)
log(`process.env.GITHUB_API_ACCESS_TOKEN =\n`, process.env.GITHUB_API_ACCESS_TOKEN)
// const access_token = process.env.GITHUB_API_ACCESS_TOKEN;
btoa(`process.env.GITHUB_API_ACCESS_TOKEN`)
// "cHJvY2Vzcy5lbnYuR0lUSFVCX0FQSV9BQ0NFU1NfVE9LRU4="
# bin cli
$ chmod +x ./env.js
# OR
$ chmod 777 ./env.js
$ export GITHUB_API_ACCESS_TOKEN=cHJvY2Vzcy5lbnYuR0lUSFVCX0FQSV9BQ0NFU1NfVE9LRU4= && ./env.js
# Linux / macOS, using export command
$ export GITHUB_API_ACCESS_TOKEN=cHJvY2Vzcy5lbnYuR0lUSFVCX0FQSV9BQ0NFU1NfVE9LRU4=
# Windows, using set command
$ set GITHUB_API_ACCESS_TOKEN=cHJvY2Vzcy5lbnYuR0lUSFVCX0FQSV9BQ0NFU1NfVE9LRU4=
临时环境变量
- Linux / macOS
# 设置 NODE_ENV 环境变量
$ export NODE_ENV=production
# 清除 NODE_ENV 环境变量
$ export NODE_ENV=
- Windows
# 设置 NODE_ENV 环境变量
$ set NODE_ENV=production
# 清除 NODE_ENV 环境变量
$ set NODE_ENV=
永久环境变量(⚠️ 不推荐,不够灵活)
修改系统的配置文件 $PATH
- vim
- VS Code
- GUI
# 当前用户
$ vim ~/.zshrc
# OR
$ vim ~/.bash_profile
# 在文件进行环境变量的设置或修改
# export NODE_ENV_PROD = production
# export NODE_ENV_DEV = development
# 修改后,需要刷新
$ source ~/.zshrc
# OR
$ source ~/.bash_profile
Flutter & Dart
github-user-language-stats bug
# cli
$ npm i -g github-user-language-stats
# process.env.GITHUB_API_ACCESS_TOKEN
$ export GITHUB_API_ACCESS_TOKEN= && gh-lang-stat
# demo
$ export GITHUB_API_ACCESS_TOKEN=cHJvY2Vzcy5lbnYuR0lUSFVCX0FQSV9BQ0NFU1NfVE9LRU4= && gh-lang-stat xgqfrms
refs
https://www.cnblogs.com/xgqfrms/p/13500721.html#4658099
https://nodejs.org/api/process.html#process_process_env
https://github.com/kentcdodds/cross-env
https://www.cnblogs.com/sorex/p/6200940.html
https://segmentfault.com/a/1190000011683741
https://github.com/xgqfrms/2020-interview-notes/blob/master/test/env.js
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!