0

I try to run this simple code but I can't find the desire output.

var express = require('express'),
    app = express(),
    path = require('path')
    cookieParser = require('cookie-parser')
    session = require('express-session');
    
    
 app.set('views', path.join(__dirname , 'views'));

  
  app.use(express.static(path.join(__dirname,'public')));
  
  
  
  var env = process.env.NODE_ENV || 'development';
  
  if(env === 'development'){
      // dev specific settings
    
       
  } else {
      //Production specific settings
      
    
  }
  

  require('./routes/routes.js')(express,app);
   
 
  app.listen (3000 , function(){
    
    console.log('Mode:'+ env);
 });

RUN ON Window CMD : > set NODE_ENV = develoment

node app.js

                > Mode : development

but when -

RUN ON Window CMD : > set NODE_ENV = production

node app.js

                > Mode : development // again same thing 
0

2 Answers 2

1

Remove spaces around equals sign set NODE_ENV=production
or try running the code like this NODE_ENV=production node app.js

Sign up to request clarification or add additional context in comments.

3 Comments

Can you explain why this happen with Space ??
It's just a way the system variable assignment works. Everything after equals sign is treated as a value of the variable. The same thing applies to OSX and Linux systems
it expect space as parameter
0

Try this Using console log verify your output. Remove spaces around equals sign set NODE_ENV=production or try running the code like this NODE_ENV=production node app.js

var express = require('express'),
    app = express(),
    path = require('path')
    cookieParser = require('cookie-parser')
    session = require('express-session');


 app.set('views', path.join(__dirname , 'views'));


  app.use(express.static(path.join(__dirname,'public')));



  var env = process.env.NODE_ENV || 'development';

  if(env == 'development'){
      // dev specific settings
      console.log("Development");

  } else {
      //Production specific settings
      conosole.log("Production");

  }



  require('./routes/routes.js')(express,app);   

  app.listen (3000 , function(){

    console.log('Mode:'+ env);
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.