0
當我運行我的節點js應用程序給出節點app.js,設置NODE_ENV = production時,它沒有被設置爲生產,而是它讓連接超時錯誤運行該應用程序。我希望它實際上與蒙哥拉相關請等待您的建議。先謝謝你。在node.js中運行應用程序時,連接超時錯誤
C:\Users\Desktop\myapp>node app.js
ChatBox working on port 3000
Mode:development
C:\Users\Desktop\myapp\node_modules\mongoose\node_modules\mongodb\lib\se
rver.js:228
process.nextTick(function() { throw err; })
^
Error: connect ETIMEDOUT
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
這是我app.js程序
var express = require('express'),
app = express(),
path =require('path'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
config = require('./config/config.js'),
ConnectMongo = require('connect-mongo')(session)
mongoose = require('mongoose').connect(config.dbURL)
app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('hogan-express'));
app.set('view engine' , 'html');
app.use(express.static(path.join(__dirname,'images')));
app.use(cookieParser());
//app.route('/').get(function(req,res,next){
// res.render('index', {title:'Welcome to ChatBox'});
//})
var env = process.env.NODE_ENV || 'development';
if(env ==='development'){
app.use(session({secret:config.sessionSecret,
saveUninitialized:true,
resave:true}))
}
else
{
app.use(session({
secret:config.sessionSecret,
saveUninitialized:true,
resave:true,
store:new ConnectMongo({
url:config.dbURL,
stringify:true
})
}))
}
var userSchema = mongoose.Schema({
username:String,
password:String,
fullname:String
})
var Person = mongoose.model('users',userSchema);
var Kajol= new Person({
username:'Kajol',
password:'kajol_123',
fullname:'Kajol Sakshi'
})
Sunitha.save(function(err){
console.log('done');
})
require('./route/route.js')(express , app);
app.listen(3000,function(){
console.log('ChatBox working on port 3000');
console.log("Mode:" +env);
})
我development.json
這是假網址。我沒有張貼了我的原始URL here.Just的格式
{
"dbURL" :"mongodb://chatboxuser:[email protected]:41603/chatbox",
"sessionSecret":"ALKKLHFDOI7UW98U3209UNFER923YH"
}
你是如何「設置NODE_ENV =生產」?您應該使用:'設置NODE_ENV = production && node app.js'來設置Windows中Node的生產模式。 – usandfriends
超時錯誤發生在生產和開發中。但是,當我設定生產時,它不會將生產模式改變爲生產模式,並且仍然處於發展過程中,並且不會改變錯誤。 –
我編輯它,只上傳,它的虛擬URL,你有任何想法警告? –