How to use the env function from process

Find comprehensive JavaScript process.env code examples handpicked from public code repositorys.

process.env is a Node.js global object that contains information about the environment in which the current process is running, including things like operating system, user data, and custom environment variables.

21
22
23
24
25
26
27
28
29
const Logger = require('../js/logger');

const logger = new Logger(getLogStream('stderr'));

const CDN_URL =
  process.env.SENTRYCLI_LOCAL_CDNURL ||
  process.env.npm_config_sentrycli_cdnurl ||
  process.env.SENTRYCLI_CDNURL ||
  'https://downloads.sentry-cdn.com/sentry-cli';
fork icon219
star icon808
watch icon60

+ 13 other calls in file

9
10
11
12
13
14
15
16
17
18
// 指定日期
var startDate = '2017-06-20';
var endDate = '2017-06-22';
var granularity = 'day';
var accessKey = proc.env.QINIU_ACCESS_KEY;
var secretKey = proc.env.QINIU_SECRET_KEY;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

var cdnManager = new qiniu.cdn.CdnManager(mac);
// 获取域名带宽
fork icon188
star icon579
watch icon37

+ 7 other calls in file

How does process.env work?

process.env is a property of the Node.js process object that provides access to the environment variables that were set when the Node.js process was started. It is an object containing key-value pairs representing the current user environment.

12
13
14
15
16
17
18
19
20
21
22
});


describe('test util functions', function () {
    var accessKey = proc.env.QINIU_ACCESS_KEY;
    var secretKey = proc.env.QINIU_SECRET_KEY;
    var bucket = proc.env.QINIU_TEST_BUCKET;
    var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    var config = new qiniu.conf.Config();
    var bucketManager = new qiniu.rs.BucketManager(mac, config);

fork icon189
star icon577
watch icon38

+ 8 other calls in file

54
55
56
57
58
59
60
61
62
if (databaseConfig.sshTunnelCommand) {
  startSshTunnel(databaseConfig.sshTunnelCommand);
}

if (isProduction) {
  process.env.NODE_ENV="production";
} else {
  process.env.NODE_ENV="development";
}
fork icon99
star icon456
watch icon14

+ 3 other calls in file

Ai Example

1
2
3
4
5
// Get the value of the NODE_ENV environment variable
const env = process.env.NODE_ENV;

// Print out the value of the environment variable
console.log(`The value of NODE_ENV is: ${env}`);

In this example, we're using process.env to access the NODE_ENV environment variable and store its value in the env variable. We then use console.log() to print out the value of the environment variable to the console.

14
15
16
17
18
19
20
21
22
23
const packageJSON = require('./package.json');
const process = require('process');

const logger = LoggerFactory.createLogger(
        'Stream Service',
        process.env.STREAMSHEETS_STREAMS_SERVICE_LOG_LEVEL
);
metadata.version = packageJSON.version;

process.on('unhandledRejection', (error) => {
fork icon51
star icon418
watch icon30

158
159
160
161
162
163
164
165
166
167
    let humanMillisecond = (baseDate.getMilliseconds() < 10 ? '0' : '') + baseDate.getMilliseconds();
    let HumanizedDateTime = (humanYear + "-" + humanMonth + "-" + humanDate + " @" + humanHour + "h " + humanMinute + "m " + humanSecond + "s " + humanMillisecond + "ms");
    return HumanizedDateTime;
};

var is_colab = process.env.colaburl !== undefined;
var charactersPath = 'public/characters/';
var chatsPath = 'public/chats/';
const jsonParser = express.json({ limit: '100mb' });
const urlencodedParser = express.urlencoded({ extended: true, limit: '100mb' });
fork icon89
star icon393
watch icon12

+ 3 other calls in file

142
143
144
145
146
147
148
149
150
151
mainWindow.webContents.on('new-window', function (e, url) {
  e.preventDefault();
  shell.openExternal(url);
});

const envStartUrl = isPackaged ? null : process.env.ELECTRON_START_URL
const startUrl = envStartUrl || url.format({
  pathname: joinPath(__dirname, '..', 'build', 'index.html'),
  protocol: 'file:',
  slashes: true
fork icon10
star icon83
watch icon6

48
49
50
51
52
53
54
55
56
57
  }
}

if (process.env.CLID) CLUSTER_ID = Number(process.env.CLID);

const PORT = process.env.PORT || 8080;

console.log(`
*** 5000choyen API Server v${APP_VER} ***
(C)2021 CyberRex
fork icon6
star icon66
watch icon3

+ 11 other calls in file

5
6
7
8
9
10
11
12
13
14
const path = require('path');
const process = require('process');
const ON_DEATH = require('death')({ debug: false });
const logger = require('../src/logger')();

const env = process.env;
// Honestly, not sure what this is. Took it from the seed project
function envOrArg(name, defaultValue) {
        let lc = name.toLowerCase();
        let uc = name.toUpperCase();
fork icon1
star icon11
watch icon9

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
  if (args.length === 0 || (!args[0] && !process.env.PUBLIC_DOMAIN)) {
    console.error(usage);
    process.exit(-1);
  }

  const publicDomain = args[0] || process.env.PUBLIC_DOMAIN;
  updateManifests(publicDomain);
}

function updateManifests(publicDomain) {
fork icon1
star icon8
watch icon3

15
16
17
18
19
20
21
22
23
24
    .use(serveStatic(path.join(__dirname, '../.tmp'), STATIC_OPTIONS))
    .use(serveStatic(path.join(__dirname, '../app'), STATIC_OPTIONS));

var server = http.createServer(api);
socket(server);
var port = process.env.PORT || 9000;

server.listen(port).on('error', function (e) {
  if (e.code !== 'EADDRINUSE' && e.code !== 'EACCES') {
    throw e;
fork icon616
star icon0
watch icon70

+ 11 other calls in file

7
8
9
10
11
12
13
14
15
16
const process = require('process');

class Plugin extends Bot {
  constructor () {
    super();
    const { caiyun_key, caiyun_gps } = process.env;
    if (!caiyun_key || !caiyun_gps) {
      console.error('! 请先配置secrets:caiyun_gps,caiyun_key');
      return this.exit();
    }
fork icon107
star icon67
watch icon3

4
5
6
7
8
9
10
11
12
 * @readonly
 */
exports.URL_GREP = /^https:\/\/github\.com\/([\w\-]+)\/([\w\-\.]+)\/issues\/?$/

exports.CLIENT_ID = process.env.CLIENT_ID
exports.CLIENT_SECRET = process.env.CLIENT_SECRET

exports.GITHUB_API = 'https://api.github.com'
exports.SELF_DOMAIN = 'rss.mrcodex.com'
fork icon2
star icon25
watch icon0

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
console.log('***************************************************************************')
console.log('Open Digital Architecture - Component Test Kit CTK Level 2 Dynamic Tests')
console.log('***************************************************************************')
console.log()

const NAMESPACE = process.env.NAMESPACE
const HEADER = process.env.HEADER
const components = process.env.components.split(',')
for (const index in components) {
  const componentEnvelopeName = components[index]
fork icon4
star icon6
watch icon20

+ 5 other calls in file

25
26
27
28
29
30
31
32
33
34
  if (process.env.LT_USERNAME) {
    console.log(
      "Setting user name from environment",
      process.env.LT_USERNAME
    );
    lt_config["lambdatest_auth"]["username"] = process.env.LT_USERNAME;
  }
} else if (
  process.env.LT_USERNAME &&
  (!("lambdatest_auth" in lt_config) ||
fork icon17
star icon4
watch icon7

+ 15 other calls in file

7
8
9
10
11
12
13
14
15
16


const https = require('https');
const process = require('process');

const APIKEY = process.env.APIKEY || process.argv[2];
const GROUP = process.env.GROUP || process.argv[3] || "wg/rdf-star";

if (!APIKEY) {
  console.error('Error: APIKEY must be specified as either an environment variable or a command-line argument.');
fork icon0
star icon2
watch icon20

+ 3 other calls in file

182
183
184
185
186
187
188
189
190
191
I've chosen to use [`autocannon`][autocannon] so I needed to write a request generation script which looks like this:

```javascript
const process = require('process')

const POST_COUNT = process.env.TEST_POST_COUNT
  ? parseInt(process.env.TEST_POST_COUNT, 10)
  : undefined
const USER_COUNT = process.env.TEST_USER_COUNT
  ? parseInt(process.env.TEST_USER_COUNT, 10)
fork icon0
star icon1
watch icon2

+ 7 other calls in file

62
63
64
65
66
67
68
69
70
71
describe("access process.std[xx]", () => {
    const child_process = require('child_process');
    const io = require('io');
    const os = require('os');

    process.env.CI && it("test process.stdout in this proc", () => {
        // access it
        process.stdout;

        const LEN = 100
fork icon311
star icon0
watch icon0

2
3
4
5
6
7
8
9
10
11
12
const fs = require('fs');
const readline = require('readline');
const CommonUtils = require("./CommonUtils")
const appSpecificErrors = require('./appSpecificErrors');
const process = require('process')
const env = process.env


let port = 0
const subscriptionBook = new Map()
const virtualSubscriptionBook = new Map()
fork icon4
star icon0
watch icon2

+ 6 other calls in file