问题
I am trying to deploy this nodeJS server as web API app in azure and I can't seem to get this running, after fixing verious object i keep getting other errors and can't seem to get this api up and running. so please helpe me out. here is the error I am getting:
I'm using the debugconsole to check if this node can be deployed and this is where i keep getting error after error but i just can't seem to be able to get this api up and running PLEASE HELP.
回答1:
getaddrinfo ENOTFOUND
means mongodb client was not able to connect to given address.
You can try to check your mongodb server
locally, E.G.
I create a mongodb server on an ubuntu VM on Azure as Install MongoDB on a Windows VM shows, then leverage the following code snippet, which works fine on my side:
var MongoClient = require('mongodb').MongoClient;
var connectionString = 'mongodb://<server_name>.cloudapp.net:27017/';
MongoClient.connect(connectionString,function(err,db){
if(err){
console.log(err);
res.send(200,{message:'Something went wrong when connecting to db'});
}else{
db.close();
res.send(200,{message:'Connected correctly to db'});
}
})
update
I create a simple test code project on Azure Web Apps try to reproduce the issue, but it works fine on my side, I'd like to point out my env and code snippet for your information:
my dependencies:
"dependencies": {
"jade": "*",
"express": "~3.1.0",
"mongoose":"*"
},
my code snippets of mongoose with MongoLab connectionString:
exports.index = function(req, res){
var mongoose = require('mongoose');
mongoose.connect('mongodb://<dbuser>:<dbpassword>@ds058048.mongolab.com:58048/<dbname>');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
console.log('db open!');
res.send(200,{message:'Connected correctly to db'});
});
};
And the connectionstring is shown as Quick-Start Guide to MongoLab mentions.
来源:https://stackoverflow.com/questions/34712509/error-when-deploying-nodejs-server-in-web-api-app-azure