在 Web api 应用 Azure 中部署 nodejs 服务器时出错 [英] Error when deploying nodejs server in web api app Azure

查看:39
本文介绍了在 Web api 应用 Azure 中部署 nodejs 服务器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此 nodeJS 服务器部署为 azure 中的 Web API 应用程序,但我似乎无法运行它,在修复了很多对象后,我不断收到其他错误,似乎无法启动并运行此 api.所以请帮帮我.这是我得到的错误:

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:

我正在使用 debugconsole 来检查是否可以部署此节点,这是我在错误后不断出错的地方,但我似乎无法启动并运行此 api,请帮助.

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.

推荐答案

getaddrinfo ENOTFOUND 表示 mongodb 客户端无法连接到给定地址.

getaddrinfo ENOTFOUND means mongodb client was not able to connect to given address.

您可以尝试在本地检查您的 mongodb 服务器,例如

You can try to check your mongodb server locally, E.G.

我在 Azure 上的 ubuntu VM 上创建了一个 mongodb 服务器作为 在 Windows 虚拟机上安装 MongoDB 显示,然后利用以下代码片段,这对我来说效果很好:

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'});
    }
})

更新

我在 Azure Web Apps 上创建了一个简单的测试代码项目尝试重现该问题,但在我这边运行良好,我想指出我的 env 和代码片段以供参考:

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:

我的依赖项:

"dependencies": {
    "jade": "*",
    "express": "~3.1.0",
    "mongoose":"*"
  },

我的带有 MongoLab connectionString 的 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'});
    });
};

连接字符串显示为 MongoLab 快速入门指南 提及.

And the connectionstring is shown as Quick-Start Guide to MongoLab mentions.

这篇关于在 Web api 应用 Azure 中部署 nodejs 服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆