Node Application的app.js文件出错

时间:2016-01-14 18:19:24

标签: node.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
    
       
  } else {
      //Production specific settings
      
    
  }
  

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

RUN ON Window CMD:>设置NODE_ENV =开发

  

节点app.js

                > Mode : development

但是 -

RUN ON Window CMD:>设置NODE_ENV =生产

  

节点app.js

                > Mode : development // again same thing 

2 个答案:

答案 0 :(得分:1)

删除等号NODE_ENV=production node app.js周围的空格或尝试运行此代码main()

答案 1 :(得分:0)

尝试此操作使用控制台日志验证输出。 删除等号符号集NODE_ENV = production周围的空格 或者尝试像这样的NODE_ENV =生产节点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);
 });