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=

临时环境变量

  1. Linux / macOS
# 设置 NODE_ENV 环境变量
$ export NODE_ENV=production # 清除 NODE_ENV 环境变量
$ export NODE_ENV=
  1. Windows
# 设置 NODE_ENV 环境变量
$ set NODE_ENV=production # 清除 NODE_ENV 环境变量
$ set NODE_ENV=

永久环境变量(️ 不推荐,不够灵活)

修改系统的配置文件 $PATH

  1. vim
  2. VS Code
  3. 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=<your token> && gh-lang-stat <github username>
# 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 发布文章使用:只允许注册用户才可以访问!


how to config custom process.env in node.js的更多相关文章

  1. 极简 Node.js 入门 - 2.3 process

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

  2. [Node.js] 06 - Multi-thread and process module

    课前阅读:关于Node.js后端架构的一点后知后觉 书推荐:<Node.js design patterns> 衍生问题: 微服务的必要性,Flux架构 容错性和拓展性 一.立体拓展 假设 ...

  3. Node.JS学习——学习笔记

    Node.JS--学习笔记 2020年02月23日11:52:01 我打算自学NodeJS-通过阅读NodeJS官网来完成. https://nodejs.org/dist/latest-v13.x/ ...

  4. 深入理解 Node.js 进程与线程

    原文链接: https://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651557398&idx=1&sn=1fb991da ...

  5. Node.js的net模块

    net模块提供了一个异步网络包装器,用于TCP网络编程,它包含了创建服务器和客户端的方法 创建TCP服务器 net.createServer方法 创建客户端去连接服务器 net.connect方法 简 ...

  6. [Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive

    PM2 is a production process manager for Node.js applications with a built-in load balancer. It allow ...

  7. Node.js学习笔记(四): 全局对象

    在浏览器 JavaScript 中,通常 window 是全局对象, 而 Node.js 中的全局对象是 global,所有全局变量(除了 global 本身以外)都是 global 对象的属性. 这 ...

  8. node.js 运行机制与简单使用

    一.hello world 1.引入 required 模块 2.创建服务器 3.接收请求与响应请求 var http = require('http'); // 载入http模块 http.crea ...

  9. Practical Node.js摘录(2018版)第1,2章。

    大神的node书,免费 视频:https://node.university/courses/short-lectures/lectures/3949510 另一本书:全栈JavaScript,学习b ...

随机推荐

  1. 一文打尽 Linux/Windows端口复用实战

    出品|MS08067实验室(www.ms08067.com) 本文作者:Spark(Ms08067内网安全小组成员) 定义:端口复用是指不同的应用程序使用相同端口进行通讯. 场景:内网渗透中,搭建隧道 ...

  2. Architecture and design 洋葱 中间件 装饰器

    Go kit - Frequently asked questions https://gokit.io/faq/ Architecture and design Introduction - Und ...

  3. 跨度实际上是用来计算排位(rank) 目标节点在跳跃表中的排位 有序集 排序计算

    跳跃表的实现 - Redis 设计与实现 http://redisbook.com/preview/skiplist/datastruct.html 有序集合 /* ZSETs use a speci ...

  4. 墓碑机制与 iOS 应用程序的生命周期

    ① 应用程序的状态 iOS 应用程序一共有 5 种状态: Not running:应用未运行 Inactive:应用运行在 foreground 但没有接收事件 Active:应用运行在 foregr ...

  5. 在这个示例中,使用 watch 选项允许我们执行异步操作 (访问一个 API),限制我们执行该操作的频率,并在我们得到最终结果前,设置中间状态。这些都是计算属性无法做到的。

    在这个示例中,使用 watch 选项允许我们执行异步操作 (访问一个 API),限制我们执行该操作的频率,并在我们得到最终结果前,设置中间状态.这些都是计算属性无法做到的.

  6. PowerBI官方文档

    Excel 帮助和学习 - Microsoft 支持https://support.microsoft.com/zh-cn/excel Power Query M 公式语言引用 - PowerQuer ...

  7. SpringBoot整合JavaMail发送邮件

    JavaMail是SUN提供给广大Java开发人员的一款邮件发送和接受的一款开源类库,支持常用的邮件协议,如:SMTP.POP3.IMAP,开发人员使用JavaMail编写邮件程序时,不再需要考虑底层 ...

  8. Golang内建库学习笔记(2)-web服务器相关

    package main import ( "net/http" "fmt" "strings" "log" ) fun ...

  9. ubuntu 安装新版的qq,可支持下载文件等常用功能

    说明:此版本的QQ基本完美,但是有个缺点就是历史记录有些会显示乱码! 注意:此方法能完美解决这篇文章http://www.cnblogs.com/EasonJim/p/7118693.html的所有问 ...

  10. leetcode常见问题

    开学了 开始每日刷leetcode了  ,开一个新分类记录做题过程和心得. 1.出现本地调试无问题但提交后报错时,很有可能是全局变量导致的,解决办法 (1).尽量写成局部变量,函数尽量传参进入. (2 ...