我的應用程序文件夾結構是這樣的。Express JS無法識別環境
應用程序/ 配置/ app.js env.js server.js
每當我開始我跑我app.js文件,它給我的服務器開始在不確定的。 這是代碼的要點。
server.js
// Module dependencies.
var http = require('http'),
app = require('./config/app')();
// Start server
app.listen(app.get('port'), function(){
console.log('App is Up at '+ app.get('port') + ' as ' + process.env.NODE_ENV);
});
config/app.js
var express = require('express'),
path = require('path'),
ejs = require('ejs');
module.exports = function() {
var app = express();
var publicDir = path.join(__dirname, '../public');
// Store all environment variables
app.set('port', process.env.PORT || 3000);
// Basic configuration
app.configure(function() {
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(publicDir));
});
// Environment specific configuration
require('./env')(app);
return app;
};
config/env.js
var express = require('express'),
hbsPrecompiler = require('handlebars-precompiler'),
path = require('path');
module.exports = function(app) {
// development compile Handlebars and show errors
app.configure('development', function(){
app.set('db-uri', process.env.MONGOLAB_URI || 'mongodb://localhost/App');
hbsPrecompiler.watchDir(
path.join(__dirname, "../public/templates"),
path.join(__dirname, "../public/templates/compiled/templates.js"),
['handlebars', 'hbs']
);
app.use(express.errorHandler());
});
app.configure('production', function(){
app.set('db-uri', process.env.MONGOLAB_URI);
});
};
節點server.js
輸出
/usr/bin/node app.js
App is Up at 3000 as undefined
可以請您輸入顯示啓動服務器時的確切輸出。 – Kamrul
@Kamrul在最後添加。 –