我有一個簡單的使用MEAN的REST API。它在Heroku上託管,並且一切正常。但是,如果我嘗試在本地主機上運行它,我會收到以下錯誤:節點應用程序在Heroku上運行,但不在本地主機上運行
TypeError: Parameter "url" must be a string, not undefined
at Url.parse (url.js:81:11)
at Object.urlParse [as parse] (url.js:75:5)
at module.exports (/Users/ricardotaboada/Desktop/sbackend/node_modules/mongodb/lib/url_parser.js:15:23)
at connect (/Users/ricardotaboada/Desktop/sbackend/node_modules/mongodb/lib/mongo_client.js:403:16)
at Function.MongoClient.connect (/Users/ricardotaboada/Desktop/sbackend/node_modules/mongodb/lib/mongo_client.js:227:3)
at Object.<anonymous> (/Users/ricardotaboada/Desktop/sbackend/server.js:15:21)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
任何想法發生了什麼?非常感謝。
編輯:這裏是連接到蒙戈代碼:
mongodb.MongoClient.connect(process.env.MONGODB_URI, function (err, database) {
if (err) {
console.log(err);
process.exit(1);
}
sbrdcontroller = new controller(database);
console.log("Database connection ready");
// Initialize the app.
var server = app.listen(process.env.PORT || 3000, function() {
var port = server.address().port;
console.log("App now running on port", port);
});
});