The-NodeJS-Master-Class icon indicating copy to clipboard operation
The-NodeJS-Master-Class copied to clipboard

config server

Open dcjayasuriya2020 opened this issue 5 years ago • 5 comments

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;

  1. 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?

dcjayasuriya2020 avatar Jan 07 '21 21:01 dcjayasuriya2020

Can you provide the config file? And the require line in the index.js?

spriggs81 avatar Jan 07 '21 22:01 spriggs81

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 .

dcjayasuriya2020 avatar Jan 07 '21 22:01 dcjayasuriya2020

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. image

avinash-n992 avatar Jun 14 '21 14:06 avinash-n992

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;

Danbaba1 avatar Jul 21 '22 08:07 Danbaba1

const config = require('./config');

Danbaba1 avatar Jul 21 '22 08:07 Danbaba1