Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is a follow-on to my previous question: Enforcing set environment variables Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env[key] = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env[key] = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env[key] = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);
Correct mis-setting of key value in env.
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env.keyenv[key] = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env.key = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env[key] = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);
remove logging and redundant return
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env.key = data;
 console.log("Setting environment variable " + key + " from " + filePath);
 return;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env.key = data;
 console.log("Setting environment variable " + key + " from " + filePath);
 return;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);

This is a follow-on to my previous question: Enforcing set environment variables

While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process environment variables as a starting point for understanding how the systems work.

This part of the system checks to see if a 'default' value exists for an environment variable. If there is a default, and the variable is not set, then the variable is set to the default's value. Default values are stored in a file in a pre-defined directory (the same folder as the script file).

After taking in the review suggestions, and some other suggestions from colleagues, I have changed the code mechanism to use a map/filter/process system on the files. This makes the code quite a bit neater.

Note: this code is a file/module in a node.js application deployed in a Bluemix host.

Again I am looking for any further insights in to how the code can be improved, and if any edge cases exist. Performance is not critical, but as I am just learning JavaScript I would appreciate any insights in to any bad practices that should be avoided so that issues are avoided later on.

In particular, I am concerned that the code is not as asynchronous as it could be, though it is a requirement that all the variables are set before the code terminates (nothing asynchronous can be incomplete).

/*jshint node:true*/
/*
 * Load various pre-determined environment variables
 * (files in this folder with .env extension).
 * Only if they have not previously been set in the environment.
 * 
 * This makes the setting of Bluemix style variables quite easy.
 */
var fs = require('fs');
var path = require('path');
var env = /\.env$/;
function isEnv(fileName) {
 return fileName.match(env);
}
function processEnv(fileName) {
 var key = fileName.replace(env, "");
 if (process.env.hasOwnProperty(key)) {
 return;
 }
 var filePath = path.join(__dirname, fileName);
 var data = fs.readFileSync(filePath, 'utf8');
 process.env.key = data;
}
fs.readdirSync(__dirname)
 .filter(isEnv)
 .forEach(processEnv);
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419
Loading
default

AltStyle によって変換されたページ (->オリジナル) /