config server
2 things:
1.
when we have to export config file to index.js, code in config should mention correct module/
in this lecture the export "environmentToExport" does not directly noticed.. as if we use "config" inside index from config.js file, then within the config file there shuold be at least the word "config"
so to export I did: export const config = environmentToExport;
- on terminal (my OS is windows), NODE_ENV=staging (or production) does not detect at all... it gives only `NODE_ENV=staging node index.js NODE_ENV=staging : The term 'NODE_ENV=staging' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + NODE_ENV=staging node index.js + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (NODE_ENV=staging:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
I tried: $setNODE_ENV="production"` not working???
can someone fix it?
Can you provide the config file? And the require line in the index.js?
How awesome is.. when I'm onnnet lecture... both production and the staging was working fornport 3000,3001 &5000,5001... Things are just now happening ... Must be a wrong directory or.. couldn't figr out wt ws went wrong which I honestly troubled for several days. ! Finaly it is just now get OK... fully working 💪
Thanks John for start supporting...
Regarding the export - import.. I think with new Node/express versions it may need proper element to detect within file.
On Fri, 8 Jan 2021, 03:56 John, [email protected] wrote:
Can you provide the config file? And the require line in the index.js?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pirple/The-NodeJS-Master-Class/issues/22#issuecomment-756425143, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARRWY6YYAE5SCUY7FRWTYQ3SYYYJRANCNFSM4VZSGAVA .
Hi,
I am still facing the issue. I tried the following command as I have Windows.
SET NODE_ENV=staging ; node index.js
But it still sets the default port and environment, even if I change in the CLI
Adding a screenshot as well.

var environment = {};
environment.staging = {
'port' : '3000',
'envName' : 'staging'
};
environment.production = {
'port' : '5000',
'envName' : 'production'
};
var currentEnvironment = typeof(process.env.NODE_ENV) == 'string' ? process.env.NODE_ENV.toLowerCase() : '';
var environmentToExport = typeof(environment[currentEnvironment]) == 'object' ? environment[currentEnvironment] : environment.staging;
module.exports = environmentToExport;
const config = require('./config');